Reputation: 57
I'm currently developing an App that is used to scan ID cards. Basically I've got everything working, except for one thing: Whenever a Tag comes near the phone, whatever other application currently is running, my Activity is being called. However, I want the tag to be read only when the Activity, telling the user to scan his ID card, is in focus.
I already tried to achieve this behaviour by setting a boolean true once the Activity is started by the user, instead of a scanned NFC tag, and setting the boolean false onPause/onStop, but those are being called nonetheless, once the tag is being scanned rendering my attempts useless.
(A behaviour similar to the one I'm trying to achieve can be observed in the app NFC Tools where the user is being told to switch focus to the right Activity in order to scan a tag. If a tag is placed near the phone while outside of the App no action is being taken.)
I'm happy to see your views on this topic.
Upvotes: 2
Views: 254
Reputation: 1906
Do not register an intent filter in the AndroidManifest.xml, but rather use the enableForegroundDispatch
and disableForegroundDispatch
methods. More detailed info you can find here: http://developer.android.com/guide/topics/connectivity/nfc/advanced-nfc.html#foreground-dispatch
Upvotes: 1