Reputation: 2223
This is the first time, I am working NFC
based feature. I am facing a problem regarding encoding NDEF message.
we tried 2 apps to write data into NFC tag, names are NDEF and TagWriter
. I am writing my data into text format.This is what my data
{name:myTag,tagDetails:{name:"myOrganization",addess:"xxxxx"}}
What I understand, both apps are encoding and injecting data into tag.The problem was while reading time.
Once I read tag, I am converting bytes to String like nfcEvent.tag.ndefMessage[0].payload
.
What are the tags written by NDEF App
, after converting exact data coming what I written into tag.
The problem with TagWritter
, After converting this tags data, it's coming in this format.
"en"{name:myTag,tagDetails:{name:"myOrganization",addess:"xxxxx"}}""
Regarding this, I did some research What I found TagWritter App
converting data into UTF-8
format.
I think because of this it's happening. may be I might wrong.
how can I solve this issue.
Note : I am using Apache cordova
to build android application.
Thanks.
Upvotes: 1
Views: 3018
Reputation: 40831
If you see something like "en" (actually a non-pritable character + a language code) prepended to your data, this suggests that your tag writer app placed the text string into an NFC Forum Text record (you can get the specification from the NFC Forum's website).
The record consists of a status byte, a language code (in US-ASCII) followed by the actual text. The upper bit (b7) of the status byte indicates if the text is encoded in UTF-8 (b7 = 0
) or UTF-16 (b7 = 1
). The lower 6 bits (b5..0) indicate the length of the language code in bytes.
So as long as the language code is 2 bytes, your solution of trimming the first three bytes will work.
However, the NFC Forum Text record type is specifically intended for human-readable text and you should probably avoid using it to store JSON objects. It would be better to use an NFC Forum external type record (or a custom MIME type record) to store your data.
Upvotes: 2
Reputation: 2223
I seen the plugin documentation,what I am using to read(chariotsolutions/phonegap-nfc
). They itself suggesting to remove unnecessary characters. So we have to write code thi format.
nfc.bytesToString(nfcEvent.tag.ndefMessage[0].payload).substring(3);
This is the link, I seen
Upvotes: 0