Reputation: 7892
I am using a Mifare NFC tag and I successfully managed to read from and write to the tag. My tag only contains a package name meaning that it starts an application or goes to the Play store if the application is not installed.
But I am struggling with the following use case:
I want to read the tag when the application start for the first time. Unfortunately, the action of the Intent used to start my application is from the type MAIN and doesn't contain any NFC information. Holding the tag near the device for a second time while the application is running, will trigger the TECH_DISCOVERED Intent
which will contain the information I need.
In short: Is it possible to fetch the content off the tag when the application is started up for the first time using the tag?
Upvotes: 1
Views: 214
Reputation: 10228
If your NDEF message on the tag consists of only an Android Application Record (AAR), you will not get a handle to the tag in the intent. You would get that if you have an intent filter that matches the first record of the NDEF message. However, AARs are treated differently by Android: intent filters for it are ignored and instead the requested app is started.
Instead of only an AAR with the package name, you should create an NDEF message containing, for example, a URL record, followed by the AAR. If you then add an intent filter for the URL with action NDEF_DISCOVERED, you will get an intent with the tag handle.
Upvotes: 2