[英]Is it possible to with one touch two Android devices exchange data via NFC?
I want to create an application to exchange information between 2 devices via NFC. 我想创建一个应用程序,通过NFC在两台设备之间交换信息。
I know how to make one mobile send information to the other using Android Beam. 我知道如何使用Android Beam让一个移动设备向另一个移动设备发送信息。 What I don't know is how two phones could send data to each other with just one touch. 我不知道的是两部手机只需轻轻一按就可以相互发送数据。
Is this possible? 这可能吗? If yes, how? 如果有,怎么样?
That depends on what you are trying to achieve and what Android version(s) you are using: 这取决于您要实现的目标以及您正在使用的Android版本:
Both devices can send one NDEF message each with no user interaction required. 两个设备都可以发送一个 NDEF消息,每个消息都不需要用户交互。 The messages cannot depend on each other (ie it's not possible that one device sends a message and the other one sends an answer to this). 消息不能相互依赖(即,一个设备不可能发送消息而另一个设备发送消息)。 You would use a combination of enableForegroundNdefPush()
and enableForegroundDispatch()
to achieve this. 您将使用enableForegroundNdefPush()
和enableForegroundDispatch()
来实现此目的。
Both devices can (theoretically) send one NDEF message per touch, but user interaction is required on both devices (ie the user needs to touch the Beam UI). 两个设备可以(理论上)每次触摸发送一个 NDEF消息,但是两个设备都需要用户交互(即用户需要触摸Beam UI)。 Moreover the Beam UI on both devices needs to be touched pretty much at the same time . 而且两个设备上梁UI需要在同一时间非常感动。 Otherwise, the Beam UI on the other device will get interrupted due to the received NDEF message. 否则,由于收到的NDEF消息,其他设备上的Beam UI将被中断。 Thus, this "solution" is not really usable. 因此,这种“解决方案”并不真正可用。 You would use a combination of setNdefPushMessage*()
and enableForegroundDispatch()
to achieve this. 您可以使用setNdefPushMessage*()
和enableForegroundDispatch()
来实现此目的。
Starting with version 4.4, Android has two new features: 从4.4版开始,Android有两个新功能:
When you combine those feature (ie you have a HCE on-host card emulation service on one device and put the second device into reader mode), both devices can communicate with each other ( real bi-directional communication ) using ISO 7816-4 APDUs. 当您将这些功能组合在一起时(即您在一台设备上安装了HCE主机卡仿真服务并将第二台设备置于读卡器模式),两台设备可以使用ISO 7816-4 APDU进行相互通信( 实际双向通信 ) 。
This is possible, as explained online here . 这是可能的,因为网上说明这里 。 There is also an API demo in the API demos provided with the SDK that discusses this. SDK中提供的API演示中还有一个API演示,可以对此进行讨论。
However, keep in mind that NFC has a very small payload size, and you're unlikely to be able to transfer any sizable data using it. 但是,请记住,NFC的有效负载大小非常小,并且您不太可能使用它传输任何可观的数据。 NFC should instead be used to quickly setup bluetooth connections, or another form of wireless transfer like WiFi direct, which can then be used to transfer larger amounts of data. NFC应该用于快速设置蓝牙连接,或者像WiFi direct这样的其他形式的无线传输,然后可以用于传输更大量的数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.