If you want to receive the NDEF discovery intent upon the start of your activity, you need to add an intent filter that triggers on the tag's NDEF message to your application manifest:
<activity ... >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
I guess you already have the above, so you will need to add an NDEF intent filter:
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
You can use either a URI based trigger:
<data android:scheme="http" android:host="mroland.at" android:pathPrefix="/test" />
Or a MIME based scheme:
<data android:mimeType="application/vnd.mroland.test" />
Or if you want to receive the NDEF discovered intent for a tag that contains only an AAR (I have to admit that I never tested this so I only assume that this should work):
<data android:scheme="vnd.android.nfc" android:host="ext"
android:pathPrefix="/android.com:pkg" />
But you have to use one of them. (At least on most devices you have to. Some devices/Android versions will accept the intent filter even without a data
element.)
</intent-filter>
</activity>
You can then get the intent in onCreate()
, onStart()
, onResume()
or wherever you want to read it using the getIntent()
method.
Note that if you don't add an intent filter for NDEF_DISCOVERED
to your manifest, an NDEF message with an AAR for your application will cause the intent action MAIN
with the category LAUNCHER
to be passed to your first activity that declares such an intent filter. In that case you will not receive the NDEF message. So if you want to receive the NDEF message you have to to declare an intent filter for NDEF_DISCOVERED
. In that case, you can choose which activity is started by the AAR by setting the NDEF_DISCOVERED
intent filter for that specific activity.