Ndef not writing the empty tag in android only
When tag is empty , then ndef.writeNdefMessage is not working its throwing error : [Error: unsupported tag api]
we are using below code: const writeDataToNfcTag = async (data) => { console.log('data-=-=-',data); try { await NfcManager.requestTechnology(NfcTech.Ndef, { alertMessage: 'Ready to write some NDEF', }); const bytes = Ndef.encodeMessage([Ndef.textRecord(data)]); console.log('bytes-=-=',bytes); if (bytes) { try{ await NfcManager.ndefHandler.writeNdefMessage(bytes);
if (Platform.OS === 'ios') {
await NfcManager?.setAlertMessageIOS('Successfully write NDEF');
}
}catch(err){
console.log('writeError-=-',err);
}
}
} catch (error) {
console.error('Error writing data to NFC tag:', JSON.stringify(error));
} finally {
await NfcManager.cancelTechnologyRequest();
}
}
After debugging the android code we found that when tag is empty then its not detecting techRequest.
Ndef ndef = (Ndef)techRequest.getTechHandle();
ndef is coming null. So please check why its happening
Same issue on our side. Did you find a solution / workaround?
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
@K-Leon Hi , we resolved this issue. The issue is in technology type we added the technology in requestTechnology and use the correct write function according to nfc technology. Here is the below code: let technology = await NfcManager.requestTechnology([NfcTech.NdefFormatable, NfcTech.Ndef],
let promise = (technology == "NdefFormatable" ? NfcManager.ndefFormatableHandlerAndroid.formatNdef(bytes) : NfcManager.ndefHandler.writeNdefMessage(bytes))
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
This issue was closed because it has been stalled for 5 days with no activity.