I am working on an NFC-application. To start my app, I am using a NDEF-tag with an AAR NDEF Record inside.
This works fine. But now I want to read the tag content wi
If you want your app to be started by your tag and want to receive the parsed NDEF message, your tag should contain the following:
Once, you have your tag containing a proper NDEF message ready, you have to create an appropriate intent filter for the activity that should receive the tag discovery event and the NDEF message that triggered it:
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
Or if you used your custom NFC Forum external type:
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="vnd.android.nfc"
android:host="ext"
android:pathPrefix="/yourdomain.com:yourtypename"/>
</intent-filter>
If your app does not have an NDEF_DISCOVERED
intent filter that matches the first record of the NDEF message on your tag and your tag contains an Android Application Record, the first activity declared in your manifest that has an intent filter for android.intent.action.MAIN
and with android.intent.category.LAUNCHER
will be started. As that activity, therefore, does not declare to expect an NFC intent it will be passed the android.intent.action.MAIN
(which does not contain the NDEF message/tag handle).
I don't know if this is correct answer but I found a fix:
<activity
android:name=".NFCScanActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
</application>
</manifest>