Android Question some troubles testing TapCard library

rbirago

Active Member
Licensed User
Longtime User
I have tested TapCard library using the good B4ATapCard sample.
A couple of questions:
1) when I place my Visa Credit Card to the device it asks to choose which app I want to couple to the nfc reader intent. I choose B4aTapCard and the app works fine.
Then i have tried to previously join the nfc reader intent to B4aTapCard using
B4X:
nfc.EnableForegroundDispatch
So my Android 12 device didn't me ask to choose the app and discovered correctly the Credit Card, but doesn't goes on with the other steps with TapCard.
The question: how to join in automatic way B4aTapCard to the nfc reader intent?

2) If I try to read a not managed Credit Card (in my trial an Amex card) TapCard doesn't activate (of course) event ips_scan_result , but, after lots of ips_command_response events, it crashes!
I noticed that during the command/response dialogues TapCard gives lots of negative answers and I am able to check for them...but how to interrupt the loop of the events that at last come to a crash?

thank you
Roberto
 

drgottjr

Expert
Licensed User
Longtime User
if you have more than 1 nfc tag reader app on your device, the system will show you a dialog with a list of apps to chose from in the event of a tag discovery.

if you have more than 1 nfc tag reader app on your device, but your app is registered to read a certain tag type that the other apps cannot recognize, then your app will launch automatically. (but since professional nfc apps register for all types of nfc tags, this is not going to happen. i mention it because it explains why your app will not be chosen automatically even though you have registered to receive the intent.)

if the system shows a list of apps, you can select the one you always want to use. (this should avoid the selection dialog).

including "nfc.EnableForegroundDispatch" is not enough; your app has to be running in the foreground. nfc tags can only be handled in the foreground.

there are only 2 ways to avoid the app selection dialog:
1) remove the other nfc apps from your device (or use a second device for testing that only has your app).
2) start your app before trying to read any tags.
note: in some android models, there is a system setting which allows the system to scan nfc tags. this is not the same as the system's handling the discovery. in other words, in the absence of any nfc reader app, android has a "hidden" system app which can scan common NDEF tags. you can turn this off if it gets in the way of your app. the only way to turn off tag discovery is to turn nfc off in system settings. (this is similar to the device's ability to read qr codes without any barcode reading app. you can turn this off, too, in camera settings. more and more, android tries to supplant separate apps to perform certain actions. translate is another example.)


there are ways to work with and around crashes. the app's (or library's author) will have to address the particularities. that said, reading nfc tags is not a simple proposition. for many reasons. failure to read a given tag is to be expected, a crash implies something else.
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…