Skip to content

Instantly share code, notes, and snippets.

@miguelcardo
Created December 22, 2014 16:33
Show Gist options
  • Save miguelcardo/7fb339c70c3f0318b182 to your computer and use it in GitHub Desktop.
Save miguelcardo/7fb339c70c3f0318b182 to your computer and use it in GitHub Desktop.
Register to NFC event
public static void enableForegroundDispatch(Activity activity, NfcAdapter adapter) {
Intent intent = activity.getIntent();
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
if(adapter.isEnabled()) {
PendingIntent tagIntent = PendingIntent.getActivity(activity, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
IntentFilter iso = new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED);
adapter.enableForegroundDispatch(activity, tagIntent, new IntentFilter[]{iso},
new String[][]{new String[]{IsoDep.class.getName()}});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment