0

I am developing two apps (with flutter) that need to pass data to each other through NFC, but I don't find any way to do it. NFC libs in flutter only can read and write data to a nfc tag, but not send it.

I've tried to make one of the devices a HCE (host card emulator) with nfc_host_card_emulation package, and using nfc_kit_manager to send an APDU command (transcieve) when reads the tag. The problem is that the transcieve method return 6F00 that means unexpected error.

Here is the code of the reader with nfc_kit_manager:

void Read() async {
    var tag = await FlutterNfcKit.poll(timeout: Duration(seconds: 10));
    if (tag.type == NFCTagType.iso7816) {
      var result = await FlutterNfcKit.transceive("00B20000020000"); //this APDU command is the same in the HCE device
      }
await FlutterNfcKit.finish();
}

And the code of HCE device:

NfcApduCommand? nfcApduCommand;
if (_nfcState == NfcState.enabled) {
    await NfcHce.init(
      
      aid: Uint8List.fromList([0x00, 0xB2, 0x00, 0x00, 0x02, 0x00, 0x00]),
     
      permanentApduResponses: false,
      
      listenOnlyConfiguredPorts: false,
    );
  }
 NfcHce.stream.listen((command) {
      setState(() {
        koko = command;
        nfcApduCommand = command;
      });
    });
final port = 0;
  
final data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];

await NfcHce.addApduResponse(port, data);
                      
EdgarX
  • 1
  • 2

0 Answers0