androidnfcemv

Android Card Emulation with HostApduService gives different tag ID each time, can't ignore it


So in my case one phone works as a reader and the other works as an emulated card using HostApduService. My problem right now is that if I touch these phones the reader will start reading the other phone that emulates the card multiple times a second. I fixed this issue when reading plastic emv cards simply by using nfcAdapter.ignore(tag, ...). But when I read a phone it always has a different tag ID, which is why I guess the nfcAdapter.ignore does nothing and it rapidly reads the phone that emulates the card.

Is there any way to ignore other phone after reader reads it? Most optimal would be to somehow have static tag ID on other phone.

Of course easiest way would be to disabling reading for some time after I read the phone once but I would like to make nfcAdapter.ignore work or other nicer solution.


Solution

  • Add your own ID to data response of the HostApduService and then your reader can read it silently and then ignore it by using the enableReaderMode API with the FLAG_READER_NO_PLATFORM_SOUNDS flag.

    You can then choose yourself to make the notification sound/vibration (so it looks like the HostApduService Tag has been ignored).

    As background in NFC by design the UID of Tags only needs to be Unique when multiple Tags are in range at the same time, thus Emulated Tags use a random ID for security purposes as this meets this requirement while making the phone untrackable via it's UID (plus also there is probably not enough UID's available to make it actually Unique)