I have a question, it is possible know the code source of explain th type of tag NFC that I read? If is a Mifare 1k or Ntag203 or another else?
protected void onNewIntent(Intent intent){
String[] techList = tag.getTechList();
for(String tech:techList) {
//I think must insert here the code
}
}
Fingerprinting of NFC tags is not quite easy. Most tags don't just tell you "I am XY". Moreover, for certain tag technologies there exist many different tags from several different manufacturers. E.g. NFC Forum Type 2 tags are made by NXP, Infineon, Kovio and others.
Finding out if a tag is MIFARE Classic is rather simple on devices with NXP's NFC chipset. On those devices you will see android.nfc.tech.MifareClassic
listed in the tech-list (result of Tag.getTechList()
method). For other NfcA
tags, you could start by doing the following:
If the tag has a 7-byte UID (get it via
Tag.getId()
), the first byte indicates the tag manufacturer's ISO 7816-6 registered chip manufacturer code. E.g.0x04
for NXP,0x05
for Infineon, etc.Once you know the chip manufacturer, you could try to send manufacturer-specific commands to the tag (e.g. for NXP tags you could send a GET_VERSION command to check if the tag is an NTAG/MF Ultralight EV1 tag or an authentication command to check if it is Ultralight C) . Some manufacturers also code further chip information into the UID.
You can scan the tags memory to find the memory size and decide upon that value what chip type it is.
When you get tag , Then using TechList you can find the exact tag Type. here is the sample:
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);
}
}
}
来源:https://stackoverflow.com/questions/24058009/nfc-tag-information