I want to start android programming to be able to transfer data between a NFC enabled smartphone and a custom device, but I am not able to find clear information about a few things
For example, my custom device has to be able to send data to the smartphone as well as receive from it. But from what I have read it is not currently possible for two way communication using NFC
How to send data between two devices using NFC in android?
or the more recent,
NFC enabled phone act as a NFC tag
But the Android developers website itself says that we can use Beam to perform peer to peer communication between two android phones, so two way communication should be possible shouldn't it?
Android Beam allows simple peer-to-peer data exchange between two
Android-powered devices. The application that wants to beam data to
another device must be in the foreground and the device receiving the
data must not be locked. When the beaming device comes in close enough
contact with a receiving device, the beaming device displays the
"Touch to Beam" UI. The user can then choose whether or not to beam
the message to the receiving device.
http://developer.android.com/guide/topics/connectivity/nfc/nfc.html#p2p
Secondly, can I use an android NFC phone as a tag writer (instead of just a reader)? That is, just send data to my custom device (or a passive NFC tag)?
The keyword in "simple peer-to-peer data exchange" is simple. Currently (Android 4.2), apps cannot do 2-way communication over Beam. However, a custom device can send multiple messages over Beam. All of these will be received by the Android device without problems, but the Android app can only send one message. You can trick the Android device, however, by resetting the RF field in your custom device. It will appear to the Android device as if a new device has appeared and it will show the "Touch to Beam" UI again.
Android NFC devices can act as both tag reader and writer.
Related
I am developing an Android+iOS app with Flutter which have several screens of user interaction and NFC screen.
On the NFC screen the users taps phones back to back (as we do with Android beam data transfer): one phone is Android phone which have app running and sending NFC NDEF message just like in this example.
On the second phone "my app" with NFC screen is running and reading the NDEF with nfc_in_flutter (there are only 3 nfc plugins in flutter and this is the only one seemed to be currently maintained) plugin and displays on the screen.
This scenario works fine on Android device, however on iOS device when I tap Android device to it nothing happens.
It does not read.
I tested simple NFC tag (not Android device) with iOS device and it reads the tag.
Could someone explain what is the reason?
Here are my assumptions, please correct me if I am wrong:
Since iOS supports only NDEF format and no HCE, I should send NDEF from Android to iOS.
What I know about Host card emulation:
In order for the device to act like a card (or use HCE), app needs to create HostApduService. While this service is running phone (and the app itself) is able to recognize the reader and if everything is fine it sends the payload. The format of the message is IsoDep (not NDEF).
On the other hand the reader side sends ADPU to establish the connection and if its ok, it receives the payload.
In the above example sender creates NDEF messages and does not act as a card (HCE) since no HostApduService created.
So if iOS supports NDEF messages, why in the world iOS device does not read the message from on Android device?
I am looking for a way to establish p2p communication between an Android phone (lets call it A) and a PN532+microcontroller (lets call them B).
By p2p I mean a scenario in which:
1. A sends some application specific data to B
2. B receives data and sends a response containing application specific data to A.
I have seen similar questions but most of them date back to 2011, stating that such functionality is not yet supported by the API. Looking at the latest API I can still only see a solution in which B is treated as a TAG.
Am I missing something or is the kind of communication I am looking for is still not supported?
When you want to specifically use NFC peer-to-peer mode, then the same answers are valid today: Android only supports Android Beam for P2P communication. Hence, you can, in general, only transmit one message into one direction and you need to tap the Beam UI each time you want to send data. However, if your interaction is exactly 1 message from Android to PN532 and then 1 message from PN532 to Android, and you are okay with tapping the Beam UI when sending from Android, you could use some tricks to first receive the message from Android, then disconnect and reconnect to send the response to Android.
When you are open to support other modes, then you have some options:
If the Android device has Android 4.4 or later and supports host card emulation (HCE): Use the PN532 in reader/writer mode and implement a HCE service on the Android side.
Otherwise, use the PN532 in host card emulation mode and access it from the Android side using the standard NFC reader/writer API (e.g. IsoDep / NfcA or NfcF).
I want to create an application to exchange information between 2 devices via NFC.
I know how to make one mobile send information to the other using Android Beam. What I don't know is how two phones could send data to each other with just one touch.
Is this possible? If yes, how?
That depends on what you are trying to achieve and what Android version(s) you are using:
Both devices with Android < 4.0
Both devices can send one NDEF message each with no user interaction required. The messages cannot depend on each other (i.e. it's not possible that one device sends a message and the other one sends an answer to this). You would use a combination of enableForegroundNdefPush() and enableForegroundDispatch() to achieve this.
At least one device with Android < 4.4
Both devices can (theoretically) send one NDEF message per touch, but user interaction is required on both devices (i.e. the user needs to touch the Beam UI). Moreover the Beam UI on both devices needs to be touched pretty much at the same time. Otherwise, the Beam UI on the other device will get interrupted due to the received NDEF message. Thus, this "solution" is not really usable. You would use a combination of setNdefPushMessage*() and enableForegroundDispatch() to achieve this.
Both devices with Android 4.4+
Starting with version 4.4, Android has two new features:
NFC reader mode and
Host-based Card Emulation (HCE).
When you combine those feature (i.e. you have a HCE on-host card emulation service on one device and put the second device into reader mode), both devices can communicate with each other (real bi-directional communication) using ISO 7816-4 APDUs.
This is possible, as explained online here. There is also an API demo in the API demos provided with the SDK that discusses this.
However, keep in mind that NFC has a very small payload size, and you're unlikely to be able to transfer any sizable data using it. NFC should instead be used to quickly setup bluetooth connections, or another form of wireless transfer like WiFi direct, which can then be used to transfer larger amounts of data.
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
Here's what I'm trying to do with 2 Galaxy Nexuses running Android 4.0 with NFC capabilities:
Device A and B are in close enough to initiate an Android Beam UI.
Device A sends a beam to Device B
Device B received beam, does some processing, and then sends a response beam back to device A
I have the initial beam from A -> B working fine but not the communication back. I do want to send something more than just an 'ACk', like a small payload of data. Is there any way to do this over NFC with the current APIs or will I have to look towards WiFi/BT p2p communication?
I don't think this is possible unless you pull the devices apart then put them together again and explicitly beam data from Device B to A with the touch to beam UI. You can use NFC to initiate a BT connection though and get the job done.
For now, (unfortunately) peer-to-peer mode is only accessible on Android through Android Beam, which can't be used for bi-directional communication.
If you want to archieve true bi-directional communication, you can better use reader/writer & card-emulation modes.
When emulate a ISO/IEC 14443-4 tag, you can use APDU commands (see ISO/IEC 7816-4) to send bi-directional information.
while the two devices are close to each other you can show a toast at B device to ensure it receive the NDEf message
I have not tried that myself, but you might be able to acheive a form of bi-directional communication by using one phone in reader/writer mode and the other phone in host based card emulation mode (HCE). See also this thread: NFC reader/writer mode - is it only for tags?.