Question

I have an NFC app that has all the proper intent filters set up in the manifest to only respond to a particular kind of NFC technology.

This part works, but I don't understand what it will do if ANOTHER app had the exact same kind of filters.

My app ignores all nfc tags except the ones of a particular type, when scanned my app pops up from onDestroyed() (or never run at all) to onCreate() and reads the info from the tag.

Now this is further filtered by the info in my tags, I put a special kind of string that my app looks for. But unfortunately this requires it to have read the tag AFTER determining what kind of technology it is. If it isn't one of MY strings, the app goes away - but I don't understand what would happen if another app was looking for the same kind of technology.

What I would prefer to happen is that my app is loaded when seeing this tag, but then goes away after ignoring it. THEN other apps with the exact same filter set could load and have their go at the tag. But I don't understand how this is handled, and I can foresee many NFC apps coming to market.

Insight appreciated.

Was it helpful?

Solution

but I don't understand what would happen if another app was looking for the same kind of technology

Presumably, the user will be presented with an activity chooser.

What I would prefer to happen is that my app is loaded when seeing this tag, but then goes away after ignoring it. THEN other apps with the exact same filter set could load and have their go at the tag.

If my activity chooser guess is correct, then the only way that this will be possible is if:

  1. The user chooses your app to be the default handler for this type of NFC tag, after installing your app and tapping a relevant tag, and

  2. You, after determining it is not your type of tag, pop up your own hand-rolled activity chooser for any other relevant activity, filtering yourself out of the list, by using PackageManager and queryIntentActivities() and such

But I don't understand how this is handled, and I can foresee many NFC apps coming to market.

I project that most NFC apps will be focused on NDEF-compatible tags, which make this a lot simpler.

OTHER TIPS

The Activity Chooser will indeed show if more than one application can handle the ACTION_TECH_DISCOVERED intent. If I understand your problem correctly, you really cannot stop the activity chooser from showing if multiple apps can handle the tag, unless you use foreground dispatching, which lets your application handle the intent, if possible, if your app is in the foreground. It will supersede any other app that can handle it and not show the activity chooser. If after checking the data and finding out its not the tag you want, I think you can potentially broadcast the intent so other apps can try to handle it. Check out:

http://developer.android.com/guide/topics/nfc/advanced-nfc.html#foreground-dispatch

for more information.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top