public static void setupForegroundDispatch(final Activity activity, NfcAdapter adapter) { 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 = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED); IntentFilter[] filters = new IntentFilter[1]; String[][] techList = new String[][]{new String[] { NfcA.class.getName()}, new String[] {NfcB.class.getName()}}; // 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); /* try { filters[0].addDataType(MIME_TEXT_PLAIN); } catch (MalformedMimeTypeException e) { throw new RuntimeException("Check your mime type."); } */ adapter.enableForegroundDispatch(activity, pendingIntent, filters, techList); }
private void setForegroundListener() { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); boolean handleFormatable = preferences.getBoolean("format_ndef_formatable_tags", false); pi = PendingIntent.getActivity(this, 0, new Intent(this,getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0); intentFiltersArray = null; if(handleFormatable) techList = new String[][]{ new String[]{ NfcA.class.getName(),Ndef.class.getName()}, new String[]{ NfcB.class.getName(),Ndef.class.getName()}, new String[]{ NfcF.class.getName(),Ndef.class.getName()}, new String[]{ NfcV.class.getName(),Ndef.class.getName()}, new String[]{ NfcA.class.getName(),NdefFormatable.class.getName()}, new String[]{ NfcB.class.getName(),NdefFormatable.class.getName()}, new String[]{ NfcF.class.getName(),NdefFormatable.class.getName()}, new String[]{ NfcV.class.getName(),NdefFormatable.class.getName()}}; else techList = new String[][]{ new String[]{ NfcA.class.getName(),Ndef.class.getName()}, new String[]{ NfcB.class.getName(),Ndef.class.getName()}, new String[]{ NfcF.class.getName(),Ndef.class.getName()}, new String[]{ NfcV.class.getName(),Ndef.class.getName()}}; }