ako89
ako89

Reputation: 55

Reading NFC Tag types "android.nfc.tech.NfcV" and "android.nfc.tech.NdefFormatable" with React Native

I am trying to read from a Bloodsugar Meter using NFC, right now on an Android, haven't tried iOS yet (don't have a phone with NFC).

I am using react-native-nfc-manager as library and the example that comes with it: https://github.com/whitedogg13/react-native-nfc-manager

I am receiving this tag:

{ "techTypes":["android.nfc.tech.NfcV","android.nfc.tech.NdefFormatable"], "id":"87C5280D002602E0"}

I can see that NfcV is covered in this library, but how do I read it as that type?

I am following the example so I haven't set anything in my manifest or my build.gradle. I have linked it and it is working, but im missing the last part it seems.

By following the example it looks like I am supposed to use a method like this:

_parseText = (tag) => {
    try {
        if (Ndef.isType(tag.ndefMessage[0], Ndef.TNF_WELL_KNOWN, Ndef.RTD_TEXT)) {
            return Ndef.text.decodePayload(tag.ndefMessage[0].payload);
        }
    } catch (e) {
        console.log(e);
    }
    return null;
}

But my tag doesn't have a ndefMessage[0].

Upvotes: 2

Views: 3070

Answers (1)

Michael Roland
Michael Roland

Reputation: 40821

Since your tag does not contain Ndef in its techTypes list, it does not contain an NDEF message. Consequently, you won't be able to read any such message. As your "tag" is a blood sugar meter, I assume that it's not even expected to contain an NDEF message.

Instead, you will have to find out what commands the blood sugar meter actually supports (probably it will support the ISO/IEC 15693 READ SINGLE BLOCK command (see here). In order to send such low-level commands, you will need to use the Generic NfcTech API by requesting the tag technology:

NfcManager.requestTechnology(NfcTech.NfcV)

You can then use the transceive method to exchange arbitrary commands:

NfcManager.transceive(...)

Upvotes: 1

Related Questions