Android NFC p2p to retrieve information - android

I was reading about Near Field Communication on Android and was wondering if there is any way to retrieve information from one phone by another. So this can be done in two ways :
Phone(Retriever) connects via NFC to another Phone(Client). The Client does not have any special application installed, but we have an application installed in the Retriever. The Retriever then fires a query and can it get some information about the Client device(say the owners email address)? (Remember no special application is installed in the Client phone).
In this scenario the Client has an appropriate application installed that captures the NFC query, parses it, retrieves the relevant data from the Client and sends back an NFC message to the Retriever.
My background research says that it should be possible through the second way. I have two questions:
1.Is it possible through the first method. If yes then how?
2.Could you suggest me some good tutorial for the second method

Both scenarios are currently not possible with Android devices. Android apps on devices with NFC can push data via NFC to another device. There is no way to query and retrieve information (pull data) via NFC on Android.
With NFC tags, the Android device acts as a card reader/writer device. In that case the Android device can interrogate the tag and retrieve information from it.

From my experience both devices must have an app that is reade to receive a NFC event, the "caller" must have the application in foreground, when it gets close to other device, the "beam" appears and the NdefMessage is sent, on the receiver each application that has an intent filter for that MIME-TYPE can get launched and process the nfc event.
The reference as a starting point is this and the project sample from the API.

Related

Android Beam - payload transfer from both devices when only one Touch To Beam?

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 :(
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.
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.
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.
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.

Android NFC still weak of API on 4.0.3

I found many weak points of Android NFC:
ndef.connect()
cannot work for NFC phone itself, only for tag. It's no way to check the connection status when other phone close to the back.
NDEF cannot interactively send/receive in two way. On the device, tap the screen to raise a message send, and then disconnected, no way to get back data immediately.
NFC api does NOT support card mode. This is so weakness point. There's so many situations need the Phone act as RFID card. Among of them, sometimes no need security element. Once the UID available, server-end can do authentication and rest of things.
I am asking for how to check the connection status after NDEF message has been sent or received complete ?
You can register your app's activity to receive a callback when NDEF push via Android Beam is completed using NfcAdapter.setOnNdefPushCompleteCallback().

Share tag NFC between two device Android

It is possible?
I state that NFC is enabled on my phone and everything looks correct
I tried with an app called NFC TagWriter by NXP but don't work.
I create a tag with this app and then I tried to listen with other device but don't work, then I installed same app on the other device but don't work.
Please help me or suggested to me another way to do(share tag NFC).
THANKS!
The Android Beam™ feature allows a device to push an NDEF message onto another device by physically tapping the devices together. This interaction provides an easier way to send data than other wireless technologies like Bluetooth, because with NFC, no manual device discovery or pairing is required. The connection is automatically started when two devices come into range. Android Beam is available through a set of NFC APIs, so any application can transmit information between devices. For example, the Contacts, Browser, and YouTube applications use Android Beam to share contacts, web pages, and videos with other devices.
Reference from Developer Documentation
Also check this for Blog , it explains how to communicate between devices.
You can have (indepedent) p2p communication in 2 directions, and enableForegroundNdefPush is deprecated now; please, use setNdefPushMessage

Android (ICS) NFC Request and response possible

I started working on android (ics) nfc applications. Now I have the scenario of using an nfc smartphone an another nfc device which should communicate with each other.
Not a real problem, but I need a kind of Request/Response scenario. Like the nfc smartphone is held in front to the nfc device and sends an key to it via nfc. The device takes the key and starts communicating with an backend system and after that sends a response back to the nfc smartphone. The smartphone gets the response, handles it, smartphone can’t be removed from device and we’re done.
But I really need the response. I did not get this done via the nfc possibilities android ics (beam) is offering.
So therefore my question. Is this somehow possible??
And if yes could somehow explain how? Like using an external library or creating an own?
I think probably you need the NFC to enable the phone's Wifi-direct then do the two-way data transfer.
Or you may need to put the phone close to the device again, then do the beam again.

Check whether the same app is running on different Android Device through NFC

I have to develop an Android app for NFC enabled Android Devices, If both phones come close listen for the intent that tells that phones are close by due to NFC. Please suggest any solution regarding that.
Thanks in advance.
Since you didn't give enough information to answer your question, I can only guess at what you are trying to achieve.
You can create an application on each device that will send out NDEF messages. If both phones have this application installed, your NDEF message handling Activity will be started via an Intent when another NFC enabled phone with your application running gets close.
You should really read thoroughly the basic documentation provided to you at the android developer guide on NFC here.
For an Android app on ICS (Android 4), you can use an Android Application Record in the NDEF message that you share via Android Beam (preferably as the last record in your message). This will guarantee that only your app will receive the message on the other device (or the user will be directed to the Google Play Store app to install it).

Categories

Resources