Renuka
Renuka

Reputation: 843

read nfc tags written by other application

I am implementing two different application. 1) one will write content on nfc tag and read 2) Read content on tags only.

But while writing tag we have to mention the package because of which my second application is unable to read the tag. Is there any way to write tag in such a way my both applications can read. Any help or code snippet will be of great help.

Thanks.

Upvotes: 0

Views: 114

Answers (1)

Rufflez
Rufflez

Reputation: 214

I now this was written a while ago, and I hope you have figured out the answer by now, but if you haven't, here is the answer:

Create 2 separate NdefRecords with the 2 applications on it. Keep the MimeType to your original writing app name if you want to use that as an intent-filter (i.e. application/vnd.company.app).

So what you do is:

NdefRecord app1 = NdefRecord.createApplicationRecord(com.company.writer);
NdefRecord app2 = NdefRecord.createApplicationRecord(com.company.reader);

byte[] payload = xyz.getBytes();
byte[] mimeBytes = "com.company.writer".getBytes();
NdefRecord record = new NdefRecord(NdefRecord.TNF_MIME_MEDIA, mimeBytes, new byte[0], payload);
NdefMessage message = new NdefMessage(new NdefRecord[]{ record, app1, app2});

Upvotes: 1

Related Questions