简体   繁体   中英

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

我想读取检测到的NFC标签中包含的NDEF内容(即标签ID,标签大小,标签类型,标签可写,目标类型和消息类型)。

I assume that you are talking about tags with NDEF content? In that case, you can do:

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());
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM