Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

android

nfc

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

like image 423
Raghu Mudem Avatar asked Dec 06 '22 15:12

Raghu Mudem


1 Answers

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

like image 130
Kamen Goranchev Avatar answered Dec 28 '22 11:12

Kamen Goranchev