I use react-native-nfc-manager (3.10.1) in an react-native application (0.62.2) and a Mifare Ultralight NFC technology on an Android device.
How can I re-establish a NFC-connection programmatically WITHOUT removing the device?
The sequence is like this:
- Approaching the device to NFC creates an NFC connection
- App reads NFC content
- App writes a request header to NFC
- App app cancels NFC connection and creates a waiting time
- case a: Device removed and approached again: App can create new connection and can move to next step -> fine
- case b: Device not removed: App should create new connection to be able to read in next step -> app can't establish new NFC connection
- App reads NFC content
This is the minimum code I am using:
// Initialising NFC Manager
await NfcManager.start();
// 1.
// Request Technology
await NfcManager.requestTechnology(NfcTech.MifareUltralight);
// Get NFC Tag information
const nfcTag = await NfcManager.getTag();
// 2.
// Read Mifare pages
const pages = await NfcManager.mifareUltralightHandlerAndroid.mifareUltralightReadPages(pageOffset)
// 3.
// Write Mifare data
await NfcManager.mifareUltralightHandlerAndroid.mifareUltralightWritePage(pageOffset, data);
// 4.b.
// Cancel NFC Connection programmatically without removing device
NfcManager.cancelTechnologyRequest();
// This step is important, because with not canceling the other device can't access the NFC-Chip to write. If I would not need this step, my desired flow would work.
// Wait for other device writing to NFC-chip (via wire, not through NFC connection)
await new Promise(resolve => setTimeout(resolve, waitTime));
// Device should not be removed during waiting in this case
// Request Technology
await NfcManager.requestTechnology(NfcTech.MifareUltralight);
// THIS DOES NOT WORK, it keeps on waiting. If I remove the device and approach it again it works
// 5.
// Read Mifare pages
const pages = await NfcManager.mifareUltralightHandlerAndroid.mifareUltralightReadPages(pageOffset)
Background to this task is, that I want to write a request header, wait for the counterpart to write the content and after a waiting time to read that content, and all steps without removing the device from the NFC-Chip.
This is the used NFC Chip and it's states diagram: