flutter-nfc-manager icon indicating copy to clipboard operation
flutter-nfc-manager copied to clipboard

PlatformException(io_exception, null, null, null) when trying to write an nfc

Open ElegantCrab opened this issue 3 years ago • 1 comments

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

ElegantCrab avatar May 20 '22 00:05 ElegantCrab

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()); }

moein-keyvani-pur avatar Jun 29 '22 10:06 moein-keyvani-pur