具有封闭阅读器应用程序的NFC卡仿真 [英] NFC card emulation with closed reader application

查看:132
本文介绍了具有封闭阅读器应用程序的NFC卡仿真的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在两个Android设备上有两个应用程序,类似于NFC示例中的CardEmulation和CardReader.

我想将数据从在一个Android设备上运行的主机卡仿真应用程序发送到在第二个Android设备上运行的读取器应用程序.当两个应用程序都在前台打开时,此方法有效.

但是,如果我关闭阅读器应用程序,则无法再向其发送数据.相反,当两个电话放在一起时,它们会激活波束传输.但是,我想让阅读器手机在两部手机放在一起时自动启动阅读器应用程序.

所以问题是:

  1. 我可以从HCE应用程序发送数据,以便当设备彼此靠近时,阅读器收到TECH_DISCOVERED意图吗? (我们不希望在Beam模式下单击其他接受按钮.)

  2. 如果不可能,HostApduService是否可以发送数据以便阅读器接收到NDEF_DISCOVERED意图?

解决方案

不幸的是,这是不可能的.由于Android NFC堆栈对其他NFC设备(点对点模式和NFC标签)实施轮询的方式,因此无法通过以下方式通过一个基于主机的卡仿真(HCE)应用程序在一个Android设备上启动阅读器应用程序另一个Android设备.

默认情况下,Android NFC堆栈会同时轮询NFC标签和NFC对等设备.结果,当两个Android设备放在一起时,它们将通过NFC对等模式自动通信,而通过读写器模式+卡仿真模式自动通信.

结果,读取器"设备无法检测到第二个设备上运行的HostApduService.因此,Android设备无法在第二个Android设备上模拟会触发应用程序(对NDEF_DISCOVERED目的甚至TECH_DISCOVEREDTAG_DISCOVERED目的进行过滤的NFC标签(包含NDEF消息). /p>

在一个Android设备(处于读取器/写入器模式)和第二个Android设备上的HCE应用程序(HostApduService)之间进行通信的唯一方法是使用

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?

解决方案

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.

这篇关于具有封闭阅读器应用程序的NFC卡仿真的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆