Reputation: 8035
If Android Application Record (AAR) is used, intent action is
android.intent.action.MAIN
So I can not know if this is normal launch or nfc launch.
I need to do slighty different things in my activity whether activity is launched normally or after nfc tag reading. I also dont want to show prompt for choosing app if there is another app on the phone with the same intent filter, e.g.:
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="text/plain" />
</intent-filter>
Upvotes: 4
Views: 1401
Reputation: 10228
If you put the AAR not as the first record of the NDEF message (so 2nd record or later) and you put an NDEF_DISCOVERED intent filter in the manifest for the first record of the NDEF message, your app will get an NDEF_DISCOVERED intent when launched from a tag. The intent will have EXTRAs containing a handle to the tag and the complete NDEF message.
If the AAR is the first record, an ACTION_MAIN intent will be sent to the app. This intent will not contain any tag or NDEF message in the EXTRAs.
To prevent your app from showing up when scanning other NFC tags, make sure that the first NDEF record has a type that is unique to your app and filter for that. The External Type was specifically designed for this purpose. (Due to the AAR in your tag, no other apps will show up when you scan it.)
Upvotes: 6
Reputation: 1832
[Edit]:
Check for payload in your intent: EXTRA_TAG or EXTRA_NDEF_MESSAGES
This extra will always be set if the intent comes from an NFC event.
[obsolete]:
Use getIntent() and check its action
Upvotes: -3