0
votes

I have been working on nfc samples for Peer-To-Peer mode. I have implemented onResume method in two different way, for initiator mode and target mode as below:

For Initiator Mode:

mAdapter.setNdefPushMessage(getTestNdefMessage(), this);

and For Target Mode:

mAdapter.enableForgroundDispatch(this, pendingIntent, null, null);

I made one android phone as an initiator and other as target and put them back to back. Here, I can listen NFC device detection sound but does not receive any call to onNewIntent on the android phone set as Target Mode.

Can anybody help me where I am wrong, in concept OR in implementation. If I enable Android NFC Beam from settings than I get notification on Initiator device for Touch to Beam. In this case I get a call to onNewIntent.

Any direction will be helpful.

1
The onNewIntent method is called when you enable Beam, right? So where is the problem? - Michael Roland
This is what my confusion is. Is it necessary to enable android beam to use nfc for p2p mode? - sam18
Android Beam is Android's only peer-to-peer mode interface. So, yes, you have to use Beam if you want to transfer anything across peer-to-peer mode with Android. - Michael Roland
If this is the case then how do I manage p2p communication if I have one android phone with NFC and other is a non-android device with NFC capability? - sam18
when I test nfc implementation with non-android device, device as NFC Initiator, device can identify my android phone's nfc but fail to send data to my android phone. I do not receive any callback. - sam18

1 Answers

1
votes

Android Beam is Android's only peer-to-peer communication functionality. So when you disable Android Beam, you device will not be able to send or receive messages over peer-to-peer mode. Consequently, onNewIntent (et al) won't fire when putting two phones together if Beam is disabled.

Android Beam is implemented on top of the NFC Forum's standard peer-to-peer mode protocol stack:

+--------------------------------------------+
| Android Beam                               |
+--------------------------------------------+
| NDEF (NFC Data Exchange Format)            |
+--------------------------------------------+
| SNEP (Simple NDEF Exchange Protocol)       |
| (or NDEF Push Protocol (NPP) for backwards |
| compatibility to pre-SNEP Android devices) |
+--------------------------------------------+
| LLCP (Logical Link Control Protocol)       |
+--------------------------------------------+
| NFCIP-1 (ISO/IEC 18092)                    |
+--------------------------------------------+

(The terminology "initiator" and "target" that you use is only relevant on the NFCIP-1 layer. Normally both parts would be implemented on an NFC device and two NFC devices would (somewhat automatically) agree on who takes the initiator role and who takes the target role.)

So, you would typically implement all layers up to SNEP in order to communicate with an Android device that has Beam. Windows Phone 8 and Blackberry already implement SNEP for peer-to-peer NDEF data exchange.