NFC tag information

后端 未结 2 1773
眼角桃花
眼角桃花 2021-01-29 15:21

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 on         


        
2条回答
  •  执笔经年
    2021-01-29 15:49

    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);
    
            }
        }
    }
    

提交回复
热议问题