Question

I found a similar answer to this question here but given I am new to both Phonegap and NFC, was wondering if someone can help me?

I was able to successfully read a NFC tag (type="text") but don't know how to extract the payload data (text) from the tag read.

In my LogCat I receive the following message

e.tag = {"isWritable":true,"id":[4,72,-35,98,93,43,-128],"techTypes":    ["android.nfc.tech.NfcA","android.nfc.tech.MifareUltralight",
"android.nfc.tech.Ndef"],"type":"NFC Forum Type 2","canMakeReadOnly":true,"maxSize":142,
"ndefMessage":[{"id":[],"type":[116,101,120,116,47,112,108,97,105,110],
"payload":[110,117,108,108],"tnf":2}]};

I can't figure out how to convert the byteArray into a string. Is there a simple way for me to do this? I am using the PhoneGap NFC Plugin https://github.com/chariotsolutions/phonegap-nfc

Hope someone can help!

Thanks!

Was it helpful?

Solution

I was finally able to solve this problem by using the PhoneGap NFC plugin. I extracted the payload from the tag read using the 1st command shown below and then converted the bytes received into a string, again by also using a method made available via the plug-in. Hope this helps someone starting off with NFC and plugin.

    some_value = nfcEvent.tag.ndefMessage[0]["payload"];
    string_value = nfc.bytesToString(some_value);

Thanks!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top