有多种类型的NFC标签(例如,超轻的Mifare,超轻的Mifare C,MIFARE经典,FeliCa的......)的。 每个标签有不同的内存大小和阅读程序。 例如:超轻型的Mifare有64字节,但MIFARE经典1K含有1千字节存储器。 要从mifare ultratralight读取数据,不需要额外的认证,但Mifare classic需要认证。 当你得到新的意向可以分析它来获取标记信息:
@Override
protected void onNewIntent(Intent intent){
getTagInfo(intent)
}
private void getTagInfo(Intent intent) {
Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
String[] techList = tag.getTechList();
for (int i = 0; i < techList.length; i++) {
if (techList[i].equals(MifareClassic.class.getName())) {
MifareClassic mifareClassicTag = MifareClassic.get(tag);
switch (mifareClassicTag.getType()) {
case MifareClassic.TYPE_CLASSIC:
//Type Clssic
break;
case MifareClassic.TYPE_PLUS:
//Type Plus
break;
case MifareClassic.TYPE_PRO:
//Type Pro
break;
}
} else if (techList[i].equals(MifareUltralight.class.getName())) {
//For Mifare Ultralight
MifareUltralight mifareUlTag = MifareUltralight.get(tag);
switch (mifareUlTag.getType()) {
case MifareUltralight.TYPE_ULTRALIGHT:
break;
case MifareUltralight.TYPE_ULTRALIGHT_C:
break;
}
} else if (techList[i].equals(IsoDep.class.getName())) {
// info[1] = "IsoDep";
IsoDep isoDepTag = IsoDep.get(tag);
} else if (techList[i].equals(Ndef.class.getName())) {
Ndef.get(tag);
} else if (techList[i].equals(NdefFormatable.class.getName())) {
NdefFormatable ndefFormatableTag = NdefFormatable.get(tag);
}
}
}
}
当你得到确切的标签,然后你要开始阅读程序该标签。 阅读标签完整的项目在这里My GitHub Repo
我很困惑,你读RFID或NFC标签? – ThomasRS
@Thomas对此抱歉,我想阅读RFID。 – J1and1
那你为什么使用NfcAdapter? (如在NFC!= RFID) – ThomasRS