开发者

Reading multiple NFC tags simultaneously in Android

开发者 https://www.devze.com 2023-02-16 06:51 出处:网络
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

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 'transcei开发者_如何学Cve 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?


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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消