Obtaining an NFC hardware identifier on Android

I want to do something fairly straightforward, but I can’t fully understand whether the method in the Gingerbread API for the identifier of the token to be verified or the hardware on board the Nexus S. What I want to be able to do is get a unique identifier for the NFC chip of the device, therefore I can register it (for example, when the device refuses the RFID reader, I can associate the device with the refusal of the account). Is this possible using existing API methods?

The piece of code that looks the most promising (but I can’t verify because I don’t have a device)

byte[] tagId = intent.getByteArrayExtra(NfcAdapter.EXTRA_ID);
+3
source share
3 answers

tagId . . , , , , :

String ByteArrayToHexString(byte [] inarray) 
    {
    int i, j, in;
    String [] hex = {"0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"};
    String out= "";

    for(j = 0 ; j < inarray.length ; ++j) 
        {
        in = (int) inarray[j] & 0xff;
        i = (in >> 4) & 0x0f;
        out += hex[i];
        i = in & 0x0f;
        out += hex[i];
        }
    return out;
}
+7

NfcAdapter.ACTION_TAG_DISCOVERED NFC .

  • , android.nfc.action.TAG_DISCOVERED:

    < action android:name="android.nfc.action.TAG_DISCOVERED"/>
    < category android:name="android.intent.category.DEFAULT"/>
    
  • :

    < uses-permission android:name="android.permission.NFC" />
    
  • :

    < uses-sdk android:minSdkVersion="9" />  
    < uses-feature android:name="android.hardware.nfc" />
    
  • , , :

    byte[] tagId = intent.getByteArrayExtra(NfcAdapter.EXTRA_ID);
    NdefMessage[] msgs = (NdefMessage[]) intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
    

:

+2

In version 2.3.3, you have a class tag, and if you get this object, you can use the getId () method,

Tag myTag = (Tag) intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);

and if you need the tag id from byte [] as "String", you need to parse it from byte to hex;).

+2
source

Source: https://habr.com/ru/post/1788165/


All Articles