Reputation: 11
I want to implement p2p between two android apps using NFC.
I have tried the cardemulator (https://github.com/googlesamples/android-CardEmulation) and cardreader (https://github.com/googlesamples/android-CardReader) Apps. they work fine.
But in this example it's only send data from cardemulator to cardreader. I want to do the other way as well.
Is it possible to send extra data within the apdu command? The data-field now contain the aid, if I change this or put extra data after the aid, my app will off course change aid, so it will not connect.
Should I send an extra apdu command with my data?
or is it not possible to do so?
Upvotes: 0
Views: 1645
Reputation: 5709
NFC Peer 2 Peer mode is not the same thing of NFC Card Reader mode.
If you want to send data between two Android App you need Android Beam to operate in Peer 2 Peer mode.
Start from here to read some about LLCP
and SNEP
protocols.
Basically what you need is to send NDEFMessage
from one device to the other using Android callback methods.
To send a NDEFMessage
with Android Beam you need to implement these two interfaces:
CreateNdefMessageCallback
OnNdefPushCompleteCallback
Into createNdefMessage()
method you must create and return a NDEFMessage
to send (here you can find a description).
Into onNdefPushComplete()
method you can do something on NDEFMessage
sending complete.
What you need is to identify which device will act as Initiator, then into createNdefMessage()
you should return a NDEFMessage to send to the other device.
On the receiving device (in NFC named Target device) you should receive NDEFMessage
into Activity.onNewIntent(Intent intent)
and manage that.
After that you can do the same thing on the other side.
Theoretically using SNEP protocol you should be able to send SNEP GET requests, but on Android this functionality have been disabled. Here you can read a discussion about Android SNEP implementation
Keep in mind that to be able to receive a NDEFMessage you must define an IntentFilter into yout manifest.xml specifying which NDEFMessage your activity must "intercept". This is an example to catch AndroidApplicationRecord NDEFMessage:
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/com.example.android.beam" />
</intent-filter>
Check this Android Beam Example
Hope that helps
Upvotes: 1