Pregunta

so, i make an NFC project, but when i write a text on a tag, my reader can't read it, is there somethin wrong with my format?

this is the text writer format code:

private NdefMessage getNoteAsNdef() {

    byte[] textBytes = mNote.getText().toString().getBytes();


    NdefRecord textRecord = new NdefRecord(NdefRecord.TNF_MIME_MEDIA, "text/plain".getBytes(),
            new byte[0] , textBytes);
    return new NdefMessage(new NdefRecord[] {
        textRecord
    });
}

thanks before

¿Fue útil?

Solución

Maybe you're running into charset encoding issues. Try the following instead to create your NdefRecord:

byte[] textBytes = mNote.getText().toString().getBytes(Charset.forName("US-ASCII"));
new NdefRecord(NdefRecord.TNF_MIME_MEDIA, "text/plain".getBytes(Charset.forName("US-ASCII")), new byte[0], textBytes);

To create a text tag you can also use the following:

byte[] textBytes = mNote.getText().getBytes();
byte[] textPayload = new byte[textBytes.length + 3];
textPayload[0] = 0x02; // 0x02 = UTF8
textPayload[1] = 'e'; // Language = en
textPayload[2] = 'n';
System.arraycopy(textBytes, 0, textPayload, 3, textBytes.length);
NdefRecord record = new NdefRecord(NdefRecord.TNF_WELL_KNOWN, NdefRecord.RTD_TEXT, new byte[0], textPayload);
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top