0

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.

Michael Roland
  • 39,663
  • 10
  • 99
  • 206
sam18
  • 631
  • 1
  • 10
  • 24
  • The `onNewIntent` method is called when you enable Beam, right? So where is the problem? – Michael Roland Feb 25 '14 at 11:41
  • This is what my confusion is. Is it necessary to enable android beam to use nfc for p2p mode? – sam18 Feb 25 '14 at 11:46
  • 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 Feb 25 '14 at 11:52
  • 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 Feb 25 '14 at 11:59
  • 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 Feb 25 '14 at 12:02
  • In order to communicate with an android device, you must implement (in your noon-android device) the SNEP protocol via the LLCP protocol to exchange NDEF messages in both directions. – pizzaani Feb 26 '14 at 12:38
  • I think you should not wory about which device is initiator and which one is target (NFC peer-to-peer mode should pretty much handle this for you transparently -- at least on many current NFC phones). As pizzaani wrote, in order to communicate with Android Beam, the other NFC device needs to either implement SNEP (NFC Forum standard) or NPP (Android proprietary & possibly depreciated???). At least Windows Phone 8 and Blackberry have native support for SNEP and can communicate withan Android device that uses Beam. – Michael Roland Feb 26 '14 at 17:33
  • So, does it mean If I want to use peer-to-peer mode between my android and non-android device, both should support SNEP protocol. and that, in android, is used when I enable Android Beam from settings? – sam18 Feb 27 '14 at 06:35
  • Yes, that's how Beam works. – Michael Roland Feb 27 '14 at 17:51

1 Answers1

1

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.

Michael Roland
  • 39,663
  • 10
  • 99
  • 206