如何在android中读取检测到的NFC标签(NDEF内容)细节?
作者:互联网
我想读取检测到的NFC标签中包含的NDEF内容(即标签ID,标签大小,标签类型,标签可写,目标类型和消息类型).
解决方法:
我假设你在谈论带有NDEF内容的标签?在这种情况下,你可以这样做:
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());
}
标签:android,nfc,ndef 来源: https://codeday.me/bug/20190716/1481157.html