简体   繁体   中英

How to send data between two devices using NFC in android?

Hi i am developing a simple application using NFC in android. The NFC api is available in android version 2.3.3 and above. The is a documentation and simple demo code to communicate NFC enabled android device and NFC tag. I find the sample code from the below link.

http://developer.android.com/resources/samples/NFCDemo/index.html

And i did not find any useful code to communicate between two android devices.Please suggest me some example how we can do p2p communication between two android devices.

Thanks in advance

Sorry if i have to disappoint you, but active p2p communication between 2 Android devices for the moment is not possible. Although you can push NDEF messages between 2 devices using p2p. This works the following way. One of the phones registers NDEF message to be pushed and as soon as the other phone enter the field of the other phone this message is exchanged. In the ICS, Beam UI appears on the sending phone to ask the user for confirmation to send the message. All this looks more like the one of the phones emulates a tag, just the difference is that LLCP protocol is used from communication.

If this behavior is good for your use-case you can find on this blog good explanation how to use achieve this:

http://www.jessechen.net/blog/how-to-nfc-on-the-android-platform/

and also look at NFCAdapter doc (enableForegroundNdefPush and enableForegroundDispatch)

http://developer.android.com/reference/android/nfc/NfcAdapter.html#enableForegroundNdefPush%28android.app.Activity,%20android.nfc.NdefMessage%29

This is possible since Android version 4.x with the Beam service. Read more

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM