Search code examples
javaandroidnfcndefandroid-applicationrecord

Detect if activity was launched normally or after NFC tag was read (without any prompt)


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>

Solution

  • [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