Is it possible to with one touch two Android devices exchange data via NFC?

你说的曾经没有我的故事 提交于 2019-12-17 20:37:44

问题


I want to create an application to exchange information between 2 devices via NFC.

I know how to make one mobile send information to the other using 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?


回答1:


That depends on what you are trying to achieve and what Android version(s) you are using:

Both devices with Android < 4.0

Both devices can send one NDEF message each with no user interaction required. The messages cannot depend on each other (i.e. 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.

At least one device with Android < 4.4

Both devices can (theoretically) send one NDEF message per touch, but user interaction is required on both devices (i.e. the user needs to touch the Beam UI). Moreover the Beam UI on both devices needs to be touched pretty much at the same time. Otherwise, the Beam UI on the other device will get interrupted due to the received NDEF message. Thus, this "solution" is not really usable. You would use a combination of setNdefPushMessage*() and enableForegroundDispatch() to achieve this.

Both devices with Android 4.4+

Starting with version 4.4, Android has two new features:

  • NFC reader mode and
  • Host-based Card Emulation (HCE).

When you combine those feature (i.e. 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.




回答2:


This is possible, as explained online here. There is also an API demo in the API demos provided with the SDK that discusses this.

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 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.



来源:https://stackoverflow.com/questions/23815555/is-it-possible-to-with-one-touch-two-android-devices-exchange-data-via-nfc

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