flutter-nfc-manager
flutter-nfc-manager copied to clipboard
PlatformException(io_exception, null, null, null) when trying to write an nfc
NfcManager.instance.startSession(onDiscovered: (NfcTag tag) async {
var ndef = Ndef.from(tag);
NdefMessage message = NdefMessage([
NdefRecord.createText('Hello World!'),
]);
try {
await ndef.write(message);
showDialog(context: context, builder: (_) => Dialog(child: Text("SUCCESS")));
NfcManager.instance.stopSession();
} catch(e) {
showDialog(context: context, builder: (_) => Dialog(child: Text(e.toString())));
NfcManager.instance.stopSession(errorMessage: e.toString());
}
return;
});
This happens every single time I try. Am I doing something wrong here?
Edit: It happens on a BISON X Pro Android 11
NfcManager.instance.startSession(onDiscovered: (NfcTag tag) async { var ndef = Ndef.from(tag); NdefMessage message = NdefMessage([ NdefRecord.createText('Hello World!'), ]); try { await ndef.write(message); showDialog(context: context, builder: (_) => Dialog(child: Text("SUCCESS"))); NfcManager.instance.stopSession(); } catch(e) { showDialog(context: context, builder: (_) => Dialog(child: Text(e.toString()))); NfcManager.instance.stopSession(errorMessage: e.toString()); } return; });This happens every single time I try. Am I doing something wrong here?
Edit: It happens on a BISON X Pro Android 11
I could fixed that using this code: var customText="faghat heidar amiralmomenin ast"; try { await ndef.write(NdefMessage([ NdefRecord( typeNameFormat: NdefTypeNameFormat.media, type: Uint8List.fromList([0x54]), identifier: Uint8List.fromList([]), payload: Uint8List.fromList( utf8.encode(customText), ), ) ])); } catch (e) { print(e.toString()); }