I am currently working on a simple app, which scans an NFC tag and reads the data from it. To implement it, I followed this example here.
For testing, I am using a real android device (Samsung Galaxy J6) and a Mifare NFC card.
At the launch of the app, everything seems fine, the NfcManager has been successfully started, the tag event has been registered (using NfcManager.registerTagEvent),but the problem occurs when requestTechnology has been called and the NFC card scanned.
The difference I noticed is regarding the intent in Android: before running requestTechnology and scanning the card against the phone, the intent and the action attached to it look like this => the action is on the main thread.
After that, the intent and the action look like this.
It seemed strange to me that the action has changed from the main thread.
The Android code is exactly like given in the link above and the code in React Native looks like this:
_read = async () => {
try {
const enabled = await NfcManager.isEnabled();
console.warn('Enabled: ', enabled);
await NfcManager.registerTagEvent((tag) => {
console.warn('Tag Discovered', tag);
}, 'Hold your device over the tag', true);
let tech = Platform.OS === 'ios' ? NfcTech.MifareIOS : [NfcTech.MifareClassic, NfcTech.NfcA];
let resp = await NfcManager.requestTechnology(tech);
let tag = await NfcManager.getTag()
.then(() => { console.warn('Tag: ', tag)})
.catch((err) => console.warn('Tag error: ', err));
{...}
// this._cleanUp();
} catch (ex) {
console.warn(ex);
this._cleanUp();
}
}
Besides that, the method requestTechnology is resolved only if the app is brought to the background and then again to the foreground right away. That also seems strange ...
Does anyone have any idea how to solve these issues and get the NFC card reading process up and running?
I appreciate your help!