I have an app with a pending intent subscribed to ACTION_NDEF_DISCOVERED and a normal intent subscribed to ACTION_TECH_DISCOVERED.
It looks like I need to have the latter intent, so that my app will come up in the NFC selection action screen.
However, with my pending intent (which is modeled after the API reference code) I have to scan the tag twice for the OnNewIntent to fire.
So a few suspicions arise:
- Do I really need two intents to capture both in app scans and out of app scans?
- Why is that the pending intent is requiring two scans? Is it because I’m subscribing with it in the manifest and in code as shown in the sample or because I have two NFC intents (albeit at different NFC intent levels) ?
Here’s the core question:
How do I make this work so that, outside of the app my app comes up in the NFC actions window and inside the app only scan is required for OnNewIntent to fire?
From your description, it looks like your set-up of the code is mostly OK. One thing you may have missed: when your app is started from the NFC actions window (the app chooser), your app’s
Activitywill be started withonCreate()and you have to retrieve the NFC intent withgetIntent(). Only after theenableForegroundDispatch()(with thePendingIntent), new NFC intents will causeonNewIntent()to be called.You could do it like this: