NFC card emulation with closed reader application

给你一囗甜甜゛ 提交于 2020-01-02 14:39:53

问题


I have two apps on two Android devices, similar to CardEmulation and CardReader from the samples for NFC.

I want to send data from the host card emulation app running on one Android device to the reader application running on the second Android device. This works when both apps are open in foreground.

But if I close the reader application, I can no longer send data to it. Instead, when the two phones are held together, they activate Beam transmission. However, I would like to have the reader phone automatically start the reader app when the two phones are held together.

So question is:

  1. Can I send data from the HCE app so that the reader receives a TECH_DISCOVERED intent when the device are put close to eachother? (We don't want the additional acceptance click for Beam mode.)

  2. If that's not possible, can the HostApduService send data so that the reader receives an NDEF_DISCOVERED intent?


回答1:


Unfortunately, that's not possible. Due to the way the Android NFC stack implements polling for other NFC devices (peer-to-peer mode and NFC tags) it is not possible to launch a reader application on one Android device through a host-based card emulation (HCE) application on another Android device.

The Android NFC stack, by default polls for both, NFC tags and NFC peer-to-peer devices. As a result, when two Android devices are held together, they will automatically communicate through NFC peer-to-peer mode and not through reader/writer mode + card emulation mode.

As a consequence, the "reader" device cannot detect the HostApduService running on the second device. Therefore, an Android device cannot emulate an NFC tag (that contains an NDEF message) that would trigger an application (that filters for an NDEF_DISCOVERED intent or even a TECH_DISCOVERED or TAG_DISCOVERED intent) on a second Android device.

The only way to communicate between one Android device (that is in reader/writer mode) and an HCE application (HostApduService) on a second Android device is by using the reader mode API). This disable peer-to-peer polling and consequently allows the reader Android device to discover the card emulation mode of the other device. However, in order to use this API your application must already have a foreground activity running on the reader device.

Note that disabling Android Beam (through the Settings app) won't disable peer-to-peer mode. So doing this won't change anything.



来源:https://stackoverflow.com/questions/37188472/nfc-card-emulation-with-closed-reader-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!