1

I want to read UID of an RFID tag with the NFC reader under javascript/Android.

The UID is set by manufacturer so that you can't copy the RFID card.

I use navigator.nfc to read NFC information but when I tap a RFID card, the resulting object called message has an array called records with only one member: message.records[0]

Inside message.records[0], there are 3 fields: data = null, mediaType = empty string, recordType = "empty".

Where is the UID?

When I use the TagInfo application, I get all information about the RFID card including the UID in the protocol information. So NFC reader is able to get them. Why not navigator.nfc?

function readWriteNfc() {
  if ('nfc' in navigator) {
    navigator.nfc.watch(function (message) {
        consoleLog("NFC message received from URL " + message);

        //now message.records[0].data is null...


      }, {mode: 'any'})
      .then(() => consoleLog("Added a watch."))
      .catch(err => consoleLog("Adding watch failed: " + err.name));
  } else {
    consoleLog('NFC API not supported.');
  }
}
Michael Roland
  • 39,663
  • 10
  • 99
  • 206
setphomn
  • 11
  • 1

1 Answers1

0

Based on the fact that you use navigator.nfc.watch(), I assume you try to use the Web NFC API, or rather one of its previous versions.

The Web NFC API is limited to NDEF messages on NFC Forum tags. You can't access any protocol parameters below the NDEF abstraction layer. Consequently, there is currently no way to read the UID of a tag using that API.

Michael Roland
  • 39,663
  • 10
  • 99
  • 206