NFC tag information

纵然是瞬间 提交于 2019-12-02 14:51:27

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:

  1. 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.

  2. 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.

  3. 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);

        }
    }
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!