I am quite new to android development and trying to read an nfc card and was wondering if it's possible to read it when the user presses a button. I know how to read a card once the card is near the reader or when it is tapped to the nfc reader (onTagDiscovered). I would like to know if it's possible when a user presses a button then the device will read the card.
Android not working as this.
AndroidManifest
that an Activity
in your application could read NFC tag. When a tag is detected by system,
Activity
is launched with discovered tag in Intent
The other solution
enableForgroundDispatch
: https://developer.android.com/guide/topics/connectivity/nfc/advanced-nfc.html#foreground-dispatch The foreground dispatch system allows an activity to intercept an intent and claim priority over other activities that handle the same intent. Using this system involves constructing a few data structures for the Android system to be able to send the appropriate intents to your application. To enable the foreground dispatch system
If multiple applications "listen" to NFC tag and your Activity
is in foreground and enableForgroundDispatch
then only your application, receive NFC discovered Tag .
With previous mechanism, you could catch all tags in your Activity
and when user press a button do required action, when user not press button, do nothing.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.