Question

I am writing an app that should be able to read from and write to nfc tags of type 1, 2, 3 and 4. I have tag1, tag2 and tag4 tags that all support NfcA technology and i want to use the NfcA class (http://developer.android.com/reference/android/nfc/tech/NfcA.html) with the trancieve(byte[]) function to send commands to the tag. How can i programatically distinguish between the tags so that i will know what communication protocol to use (commands differ for all tag types).

As an example, the following performs a read command for Tag1 and Tag2 respectively:

// Note: nfcATag is an instance of android.nfc.tech.NfcA
byte[] readTag1Bytes = nfcATag.transcieve(new byte[] {0x01, 0x00, 0x00, id[0], id[1], id[2], id[3]}); // Id[] is a byte array that contains tag id
byte[] readTag2Bytes = nfcATag.transcieve(new byte[] {0x30, 0x00})

Any help is appreciated..

Was it helpful?

Solution

NfcA is the equivalent for ISO 14443 type A and therefore you can distinguish the tags by evaluating the ATQA/SENS_RES (2 bytes) response of the transponder.
See here for a list of distinguishable tag types.

You can use the following commands:

byte[]  getAtqa()    //Return the ATQA/SENS_RES bytes from tag discovery.
Tag     getTag()     //Get the Tag object backing this TagTechnology object.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top