Reading multiple NFC tags simultaneously in Android
Asked Answered
S

3

18

The new 2.3.3 SDK includes improved NFC support, and I'd like to write an app that relies on this. Ultimately, I'd like to be able to read data from multiple tags that enter the field simultaneously, but Android only seems to trigger on the first one that enters the field - subsequent ones are ignored.

From reading the NFC spec (ISO/IEC 14443-3) for the tags I'm using (Mifare Classic), I should be able to send a 'halt' command to the tag, which will cause it to stop responding, and allow me to read the next tag in the field. Android doesn't support the halt command directly on any of the TagTechnology subclasses, so I tried sending it myself directly using transceive(new byte[] {0x50, 0x00}). This throws an IOException, with the message 'transceive failed'.

Admittedly I'm doing all this from the main thread, which I understand is a bad idea, but I just want to test the concept as easily as possible.

Is it possible to communicate with multiple tags in the field at the same time? What am I doing wrong?

Solita answered 13/3, 2011 at 5:32 Comment(0)
Z
8

What you want is unfortunately not possible at the moment, unless you do some pretty advanced hackery, which is almost never a good idea :)

Probably you could halt the card if you send the right bytes in the transceive(), as you're trying to do now. But since the halt (or rather, the HLTA which you're trying to send) is an ISO14443-3A command, this will not work through the MifareClassic interface - which uses an "encrypted" pipe. Directly transmitting over the NfcA interface unfortunately doesn't work with the current stack either.

Even if you could get the card to halt, this will not automatically cause the NFC chip in the phone to resume polling for new tags - since you are "going around" the stack.

Zhukov answered 11/4, 2011 at 15:35 Comment(1)
Thanks for the definitive answer!Solita
J
1

Depending on my short experience you can not work with multiple tags. If two tags are in the field you do not receive an ID from the tag, it's binary zero. So my guess is that, at this point, you can only access one tag and no more than one can be in the field.

Jess answered 16/3, 2011 at 8:43 Comment(3)
The RF protocol supports collision resolution and resolving multiple tags, though - so the question is, why do I get an error when trying to issue a halt to the tag I'm already reading?Solita
Simply because the SDK does not support collisions or multiple transponders at the same time. I don't know about the error but at this time you receive an Intent when a transponder enters the field, the intent is exactly for a single tag. Depending on the tag protocol you can, at this time, not find the UIDs of other tags because the SDK is too limited. A clean solution will involve an updated SDK that supports more than one tag. Of course I could imagine some "hacks" or to use the NDK to overcome the current limitation.Jess
Since it seems this is the closest we're going to get to an answer, can you update your question with the extra info?Solita
A
0

Have you had success sending other commands using transceive such as read block (0x30, 0x(block)) or authenticate sector commands? Just thinking you might want to be sure you're using transceive correctly in the first place.

Alibi answered 13/3, 2011 at 22:20 Comment(2)
Good point. I haven't tried doing anything else directly with transcieve; I'll give it a go.Solita
Calling readBlock() (after authenticating) works fine; as does calling transceive() with the same bytes as readblock() outputs. Attempting to halt the card still produces the IOException, though.Solita

© 2022 - 2024 — McMap. All rights reserved.