void setUpWriteMode() { if (!inWriteMode) { IntentFilter discovery= new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED); IntentFilter[] tagFilters=new IntentFilter[] { discovery }; Intent i= new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pi=PendingIntent.getActivity(this, 0, i, 0); inWriteMode=true; nfc.enableForegroundDispatch(this, pi, tagFilters, null); } }
@Override public void onResume() { super.onResume(); if (!inWriteMode) { IntentFilter discovery=new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED); IntentFilter[] tagFilters=new IntentFilter[] { discovery }; Intent i=new Intent(this, getClass()) .addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP| Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pi=PendingIntent.getActivity(this, 0, i, 0); inWriteMode=true; nfc.enableForegroundDispatch(this, pi, tagFilters, null); } }
private void startForegroundDispatch() { nfcAdapter.enableForegroundDispatch(this, nfcPendingIntent, nfcIntentFilters, nfcTechLists); }
@Override public void onResume() { super.onResume(); if (mAdapter != null) mAdapter.enableForegroundDispatch(this, mPendingIntent, mFilters, mTechLists); }
/** * 获得焦点,按钮可以点击 */ @Override public void onResume() { super.onResume(); //设置处理优于所有其他NFC的处理 if (mNfcAdapter != null) mNfcAdapter.enableForegroundDispatch(this, mPendingIntent, null, null); }
@Override public void onResume() { super.onResume(); if (mAdapter != null) mAdapter.enableForegroundDispatch(this, mPendingIntent, mFilters, mTechLists); }
protected void enableForeground() { if(!foreground) { Log.d(TAG, "Enable nfc forground mode"); nfcAdapter.enableForegroundDispatch(this, nfcPendingIntent, writeTagFilters, null); foreground = true; } }
protected void enableForeground() { if(!foreground) { Log.d(TAG, "Enable nfc forground mode"); nfcAdapter.enableForegroundDispatch(this, nfcPendingIntent, writeTagFilters, null); foreground = true; } }
@Override public void onResume() { super.onResume(); mNFCAdapter.enableForegroundDispatch( this, // Intent that will be used to package the Tag Intent. mNFCPendingIntent, // Array of Intent Filters used to declare the Intents you // wish to intercept. mIntentFiltersArray, // Array of Tag technologies you wish to handle. mTechListsArray); }
/** * Requests any foreground NFC activity. This method must be called from * the main thread. */ private void installNfcHandler() { Intent activityIntent = new Intent(mActivity, mActivity.getClass()); activityIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(mActivity, 0, activityIntent, PendingIntent.FLAG_CANCEL_CURRENT); mNfcAdapter.enableForegroundDispatch(mActivity, intent, mIntentFilters, mTechLists); }
/** * @param activity The corresponding {@link Activity} requesting the foreground dispatch. */ public static void setupForegroundDispatch(final Activity activity) { final Intent intent = new Intent(activity.getApplicationContext(), activity.getClass()); intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); final PendingIntent pendingIntent = PendingIntent.getActivity( activity.getApplicationContext(), 0, intent, 0); IntentFilter[] filters = new IntentFilter[1]; String[][] techList = new String[][]{}; // Notice that this is the same filter as in our manifest. filters[0] = new IntentFilter(); filters[0].addAction(NfcAdapter.ACTION_TAG_DISCOVERED); filters[0].addCategory(Intent.CATEGORY_DEFAULT); NfcAdapter adapter = NfcAdapter.getDefaultAdapter(activity); adapter.enableForegroundDispatch(activity, pendingIntent, filters, techList); }
@Override protected void onResume() { super.onResume(); NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this); if (adapter != null) { Intent intent = new Intent(getApplicationContext(), this.getClass()); intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); String[][] filter = new String[][]{new String[]{"android.nfc.tech.IsoDep"}}; adapter.enableForegroundDispatch(this, pendingIntent, null, filter); } if (passportNumberFromIntent) { // When the passport number field is populated from the caller, we hide the // soft keyboard as otherwise it can obscure the 'Reading data' progress indicator. getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); } }
@Override protected void onResume() { super.onResume(); if (mAdapter != null) { if (!mAdapter.isEnabled()) { Logger.d("NFC adapter not enabled"); promptToEnableNfc(); return; } mAdapter.enableForegroundDispatch(this, mPendingIntent, null, null); } }
MifareUltralight.class.getName()} }; nfcAdapter.enableForegroundDispatch(this, pendingIntent, intentFiltersArray, techList);
if (pi != null) { try { mNfcAdapter.enableForegroundDispatch( context, pi,
if (pi != null) { try { mNfcAdapter.enableForegroundDispatch( context, pi,
if (pi != null) { try { mNfcAdapter.enableForegroundDispatch( context, pi,