Created
December 22, 2014 16:33
-
-
Save miguelcardo/7fb339c70c3f0318b182 to your computer and use it in GitHub Desktop.
Register to NFC event
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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