0
votes

I have developped 2 Android applications. The first one, to write into an NFC tag, and the second to read the contents I have written .

So with, * The first application (WriteNFC): I'm writing into the Tag, one NDEF message who involves two NDEF records : The first record is a "text" type, and the second one is a "URL" type.

The second application (ReadNFC): I scan the Tag, in order to read the NDEF message, and display it, but not fully. I only display on screen the second record (URL). What I would like to do, is when the user selecte another android application that he installed for reading NFC Tags, this one should be able to display only the first record (Text), and not the second one (URL)?

On summary, when we scan an NFC Tag, with my application(ReadNFC), we can see just an URL (http://www.stackoverflow.com), and with other applications, we can see just a Text (Hello World).

2

2 Answers

1
votes

That is not possible using standard NDEF Text and URI record types.

But you can create your own record payload types using External Type record or Unknown record, which only your application can use.

Also check out the Android Application Record.

0
votes

This is what i did in the first application (WriteNFC)

private NdefRecord createRecord1(String data)
{  
   byte[] payload = data.getBytes(Charset.forName("UTF-8"));
   byte[] empty = new byte[] {};
   return new NdefRecord(NdefRecord.TNF_ABSOLUTE_URI, empty, empty, payload);
}
private NdefRecord createRecord2(String data)
{  
   byte[] payload = data.getBytes(Charset.forName("UTF-8"));
   byte[] empty = new byte[] {};
   return new NdefRecord(NdefRecord.TNF_ABSOLUTE_URI, payload, empty, empty);
}

And for in the second application (ReadNFC)

NdefRecord cardRecord = msg.getRecords()[1];//Extract the second Record
String url_data = new String(cardRecord.getType());//Read data type

Result:

When I read with my own application (ReadNFC), of course I had on screen only the payload of the second Record, which I stored through "Record Type". But with a third-party application, especially that natively installed ("tag"), It display correctly the first record, and for the second it's an empty field. So, It still not working, because it still see the second record screenshot