I am trying to create and write an NDEF message to an NFC tag in a Windows Form Application (written in C#) using an ACR122U NFC reader.
I have created raw bytes of the NDEF message using Andreas Jakl's NDEF library. This is the C# code:
var spRecord = new NdefTextRecord {
Text = "1",
LanguageCode = "en"
};
var msg = new NdefMessage { spRecord };
string hex = BitConverter.ToString(msg.ToByteArray());
resultBox.Text = hex.Replace('-',' ');
The output I get is D1 01 04 54 02 65 6E 31 (hexadecimal).
Then I'm writing this data to an NFC tag (MIFARE Ultralight) starting at block #5 using the following APDU commands:
CL INS P1 P2 Lc DATA IN
FF D6 00 05 04 D1 01 04 54
CL INS P1 P2 Lc DATA IN
FF D6 00 05 04 02 65 6E 31
But when I try to read that tag using Android, the written NDEF message is not recognized.
What do I need to do in order to get the NDEF message recognized by Android?
Solution (Thanks Michael Roland)
I wrote an NDEF tag using an Android app and then compared the values I have generated on that tag with the tag I wrote using the above method. The difference was 0x03 0x08 at the start. So 0x03 is a starting byte that is required and 0x08 is the length of the NDEF message.
FF D6 00 04 04 03 08 D1 01
FF D6 00 05 04 04 54 02 65
FF D6 00 06 04 6E 31 FE 00