【发布时间】:2019-09-10 07:06:19
【问题描述】:
我正在开发一个仅读取 MIFARE Classic 卡的 UID 的应用程序。但是,每次我在 Galaxy note 5 上扫描卡时,都会收到一条消息“不支持 NFC 标签类型”,并且 UID 不显示。
我知道是因为我手机的 NFC 芯片与 Mifare Classic 不兼容,但有什么办法可以解决吗?
static void showToast() {
if (NfcAdapter.ACTION_TECH_DISCOVERED.equals(getIntent().getAction())) {
Tag tag = getIntent().getParcelableExtra(NfcAdapter.EXTRA_TAG);
Toast.makeText(MainActivity.this,
"The UID for this card is:" + bin2hex(tag.getId()),
Toast.LENGTH_LONG)
.show();
}
}
static String bin2hex(byte[] data) {
return String.format("%0" + (data.length * 2) + "X", new BigInteger(1, data));
}
提前致谢。
【问题讨论】:
-
您是否注意为 ACTION_TECH_DISCOVERED 注册意图过滤器,向 xml 提供技术列表,声明使用权限 android.permission.NFC,声明使用功能 android.hardware.nfc 并调用活动的 onNewIntent() 回调中的 showToast ?
-
是的,我都做了。