美好的一天,我无法获得指示器 map ,这怎么办? 这是我的代码:
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
Log.d(TAG, "onNewIntent");
// check for NFC related actions
if (NfcAdapter.ACTION_TAG_DISCOVERED.equals(intent.getAction())) {
TextView lata = (TextView) findViewById(R.id.tv);
Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
lata.setText(tag.toString());
Tag tag1 = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
byte[] id = tag.getId();
}
}
最佳答案
继续执行以下代码行以获取标签 ID:
StringBuilder tagInfo = new StringBuilder();
byte[] tagId = tag.getId();
for (byte aTagId : tagId) {
tagInfo.append(Integer.toHexString(aTagId & 0xFF)).append(" ");
}
tagInfo.append("\n");
同时获取卡的技术列表
String[] techList = tag.getTechList();
tagInfo.append("\nTech List\n");
tagInfo.append("length = " + techList.length + "\n");
for (int i = 0; i < techList.length; i++) {
tagInfo.append(techList[i] + "\n ");
}
然后您可以执行 tagInfo.toString().trim();
并将 tagInfo 设置为您的 TextView 以显示数据。
关于java - 如何使用nfc(android studio)获取卡ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56059913/