如题,项目中会用到NFC读取卡号,并且需要获取卡的类型。
这时候我们可以在获取nfc读卡的onNewIntent方法中拿到卡的类型
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
String action = intent.getAction();
if (NfcAdapter.ACTION_TAG_DISCOVERED.equals(action)
|| NfcAdapter.ACTION_TECH_DISCOVERED.equals(action)
|| NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)) {
Parcelable parcelable = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
byte[] info = ((Tag) parcelable).getId();
HexUtil.inverted(info);
String infoHex = HexUtil.bytesToHex(info);
callbackNFC(infoHex, new BigInteger(infoHex, 16).toString());
String[] techList = ((Tag) parcelable).getTechList();
for (String s : techList) {
Logger.e("NFC读卡类型:" + s);
}
}
}
在打印的日志中我们可以看到

这里我们就可以拿到我们需要的卡类型了。
网友评论