如何读取检测机器人NFC标签(NDEF内容)的详细信息? [英] How to read detected NFC tag (NDEF content) details in android?

查看:731
本文介绍了如何读取检测机器人NFC标签(NDEF内容)的详细信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要仔细阅读说明书所检测到的NFC标签中的NDEF内容(即标签ID,标签尺寸,标签类型,是标签可写,目标类型和消息类型)。

I want to read NDEF content contained within a detected NFC tag (i.e., Tag id, Tag Size, Tag Type, Is tag Writable, Target Type, and message types).

推荐答案

我假设你正在谈论的标签与NDEF内容?在这种情况下,你可以这样做:

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

这篇关于如何读取检测机器人NFC标签(NDEF内容)的详细信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆