NFC 経由で 2 つのデバイス間で情報を交換するアプリケーションを作成したいと考えています。
Android Beam を使用して、一方のモバイルから他方のモバイルに情報を送信する方法を知っています。私が知らないのは、2 台の電話がワンタッチで相互にデータを送信できる方法です。
これは可能ですか?はいの場合、どのように?
NFC 経由で 2 つのデバイス間で情報を交換するアプリケーションを作成したいと考えています。
Android Beam を使用して、一方のモバイルから他方のモバイルに情報を送信する方法を知っています。私が知らないのは、2 台の電話がワンタッチで相互にデータを送信できる方法です。
これは可能ですか?はいの場合、どのように?
That depends on what you are trying to achieve and what Android version(s) you are using:
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.
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.
Starting with version 4.4, Android has two new features:
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.
ここでオンラインで説明されているように、これは可能です。SDK で提供される API デモには、これについて説明する API デモもあります。
ただし、NFC のペイロード サイズは非常に小さいため、これを使用して大きなデータを転送できる可能性は低いことに注意してください。代わりに、NFC を使用して Bluetooth 接続をすばやくセットアップするか、WiFi ダイレクトなどの別の形式のワイヤレス転送を使用して、大量のデータを転送する必要があります。