How to read detected NFC tag data (NDEF content) in android?

I want to read NDEF content contained in a detected NFC tag (i.e. id tag, tag size, tag type, Writable tag type, Target Type, and message types).

+3


source to share


1 answer


I'm assuming you are talking about tags with NDEF content? In this case, you can:



Tag myTag = (Tag) nfcintent.getParcelableExtra(NfcAdapter.EXTRA_TAG);

// get NDEF tag details
Ndef ndefTag = Ndef.get(myTag);
int size = ndefTag.getMaxSize();         // tag size
boolean writable = ndefTag.isWritable(); // is tag writable?
String type = ndefTag.getType();         // tag type

// get NDEF message details
NdefMessage ndefMesg = ndefTag.getCachedNdefMessage();
NdefRecord[] ndefRecords = ndefMesg.getRecords();
int len = ndefRecords.length;
String[] recTypes = new String[len];     // will contain the NDEF record types
for (int i = 0; i < len; i++) {
  recTypes[i] = new String(ndefRecords[i].getType());
}

      

+11


source







All Articles