0

Ok, I watched the Google I/O from 2011 presentation on NFC on peer to peer.

The demo was done on Gingerbread and using the application Sticky Notes found

Now in this demo, both device the onNewIntent() was called at the same time so both devices are trying to share information to one another.

On ICS and above, you have Android Beam..

With Android Beam, you have to touch to trigger the onNewIntent() event that will send the NDef message across.

Now the problem with this is that now to trigger the onNewIntent() on both devices, both user on each device has to "Touch To Beam" at the same time.

Is there a way that when you Touch To Beam on one device, both can have the onNewIntent() to be called?

I am trying to develop an app that will exchange data to each other but for it to work in a nice friendly fashion I need the devices to share the data at the same time once the Touch To Beam has been initiated on one device. I do hope this is possible.

Edit: It looks like this might not be possible to do :(

Chris
  • 5,584
  • 9
  • 40
  • 58
Springy
  • 588
  • 5
  • 15

4 Answers4

1

As far as I can tell, the feature you want is not available over NFC itself. The touch-to-beam/SNEP/NPP transfer is one direction only on Android. The user that clicks his screen will push an NDEF message to the other phone.

What I believe they've done in the video is set up a bluetooth connection with the NDEF message to make the transfer (as you saw in the stickynotes demo). Unfortunately there is no nice API for this.

However, the EasyNFC project promises to be able to allow you to create a bluetooth connection and socket between two phones/applications. Check it out here

I had a try and didn't really like the Touch-to-Beam UI that was still required in the set up of the bluetooth connection. It also didnt really suit my needs, as I wanted to transfer phone to computer and didn't really want to implement NFC P2P and a bluetooth connection.

Sam
  • 3,453
  • 1
  • 33
  • 57
  • 2
    Nope, it is via NFC p2p and gingerbread works fine. 1. If you look into the code it is obvious that it is not bluetooth as there is no libraries imported for bluetooth, and second you do not see any references to it. 2. You can simulate it on ICS above, just touch to beam at the same time on both devices. It works. Bluetooth/Wifi pairing in my eyes is a hack. It requires that both the bluetooth radios to be turned on. All I want is a small packet of information to be transmitted bi-directionally. Bluetooth and Wifi is just overkill. If I could only disable Android Beam it will work. – Springy Jun 15 '13 at 15:26
  • 1
    fair enough, i stand corrected. i agree that we need 2 way transfer with NFC but Google are having their fun with GWallet so it could be a waiting game.... i've managed to get 2 way comms going between an android phones and a computer quite nicely, but it wont work between 2 phones. – Sam Jun 17 '13 at 12:21
0

Did you try this:
Use the Touch to Beam on phone-1 to "PUSH" the data, while on the other (phone-2), use the NDEF_DISCOVERED/TECH_DISCOVERED intent to trigger/start the data capture/reception. I vaguely remember one of the above intents were triggered when a PUSH is done. Although, every transmission requires a "Touch" to start the beaming.

Joseph
  • 261
  • 2
  • 7
  • But the above will just Push the payload from phone-1 to phone-2. I want to push phone-1 to phone-2 and also phone-2 to phone-1. Basically I want both device to know that each other is here and store some data about each phone. – Springy Mar 25 '13 at 09:33
  • You have a race condition, as both devices will attempt to push. One will win the right to push. That party could disable beam once done. Then another iteration would get you what you want. – ThomasRS Mar 25 '13 at 17:35
  • 1
    The thing is you can actually get it to work. If both party Touch to beam at the same time it works as in the YouTube video above. Both devices gets each other payload. That is basically what I want really. I want the ability for both device to share information to each other with one interaction. – Springy Mar 25 '13 at 22:10
0

When you think in general, Android should not allow the NFC data transfer in both direction at the same time. Lets think of a scenario where I want to send a thing to my friend with NFC. What is actively open on my friend's phone is not important. I should send this thing even the same app is not open on the receiver side. There may be another app in my friends phone that tries to send another thing to me. When we touch our phones, Android Beam (TM) appears and he data is sent from the phone that is touched.

In you case I think you should disable Android Beam (TM) by setting setNdefPushMessage(null) and do sending both ways using the old way.

tasomaniac
  • 10,234
  • 6
  • 52
  • 84
  • Nope you can't disable it. But there are examples where you want both phones to acknowledge each other. Say you want to connect via twitter, so instead of me giving my twitter id, and your friend giving you your twitter id, you can simple touch phones together and both of you have each other id. – Springy Aug 03 '13 at 14:06
  • You can find the below explanation in the official JavaDoc below: If setNdefPushMessage() is called with a null NDEF message then NDEF push will be completely disabled for the specified activity(s). This also disables any default NDEF message the Android OS would have otherwise sent on your behalf for those activity(s). http://developer.android.com/reference/android/nfc/NfcAdapter.html#setNdefPushMessage%28android.nfc.NdefMessage,%20android.app.Activity,%20android.app.Activity...%29 – tasomaniac Aug 05 '13 at 09:04
-1

https://developer.android.com/preview/api-overview.html

I think it will be available in L!!!

NFC enhancements

Your app can invoke the Android Beam on the user’s device to share data by calling android.nfc.NfcAdapter.invokeBeam(). This avoids the need for the user to manually tap the device against another NFC-capable device to complete the data transfer.

Springy
  • 588
  • 5
  • 15
  • Hi, the right link to android.nfc.NfcAdapter.invokeBeam() is this https://developer.android.com/reference/android/nfc/NfcAdapter.html#invokeBeam(android.app.Activity) – Anchor May 24 '17 at 20:46
  • This only shows the touch to beam screen before the devices are in range. Read the documentation from @Anchor 's link: "By calling this method, an Activity can invoke the Beam animation directly even if no other NFC device is in range yet. The Beam animation will then prompt the user to tap another NFC-capable device to complete the data transfer." – Rafa0809 Dec 17 '17 at 14:55