How to send NDEF message from Android phone to iPhone with flutter - android

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?

Related

How to send notifications from a phone to device connected via BLE

I am trying to develop a companion app for a project of mine.
I want this app to relay incoming notifications on my phone to a device connected via BLE. This device will then display the text data on a screen, similar to a heads up display so that I can use it in my car and not have to go through my phone while driving (also illegal of course).
I want to know what is required for my app to be able to get notifications, and send it via BLE to the already connected device. I'd also really like to know if this can be done for an iOS app since I would prefer to end up with the final app being built for iOS. If not, android is fine for now.
This device is an ESP32 and will run its own code to execute actions when text is received.
Thank you

Emulating NDEF NFC Tag on Android phone -> Reading with iPhone/iOS core-nfc

I use a HostApduService on Android(7) to emulate an NFC forum type 4 (NDEF) tag.
Reading the NDEF text message works reliably from android, I ran into the following issues though:
When I scan the emulating phone with NXP TagInfo from another Android device, Google Play opens up since it is also listening, but the NDEF tag always gets scanned successfully.
Reading the Tag using NXP TagInfo on an iPhone(7) as a reader is different: The core NFC API looks very limited, and scanning has to be initiated by the user, accompanied by a "ready to scan" dialog. When I hold the iPhone to the Android Device, sometimes the dialog closes with the message "NFC session expired" (about 50% of the tries). When I lock the emulating Android phone, the NDEF service still runs, and the iPhone can scan the Tag with a 100% success rate.
I think I already fixed the first issue using ForegroundDispatch (the Tag Emulation is only needed when the Emulating app is shown on the screen). However, the iPhone still cancels scanning sometimes. I suppose this could also be caused by the Android phone trying to connect to the iPhone's HCE/ApplePay/whatever is there.
So I believe the cause of my problem is Android scanning for all kinds of tags while NFC is enabled.
Is there a way to disable actively scanning for passive tags from an app, while still running the HostApduService that emulates an NFC tag?
(I will update this question as soon as I get the core NFC error messages.)

a few basic questions about NFC, NDEF and NFC enabled android phones

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.

Android NFC p2p to retrieve information

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.

NFC P2P tap between android phones does not seem to work

I have developed a P2P tag-writing app using NFC for Nexus-S android phones.
The tag contains a text NDEF record and a MIME NDEF record packaged in an NDEF message.The enableForegroundNdefPush is used to enable P2P tag push from one phone to the other.NFC is enabled in both phones.
2 Nexus-S phones are being used to test the app, one for writing and the other for reading.
I am creating and writing the tag using my app present in 1 phone.The other phone is used for reading via the in-built 'Tags' application that comes with the Nexus-S. Other apps like the 'TagWriter' app from NXP has also been tested with.
Out of around 30 tests, only twice, was I able to use the above setup to read the tag.
Other times, the tapping of phones for P2P tag transfer just doesn't work. I wonder if others are having the same issue.
Thanks
Riyaz
For receiving the P2P, what are you using?
enableForegroundDispatch or general intents to determine the tags?
IF using enableForegroundDispatch, be careful as techfilter should be appropriate as being used by the app that is writing the tags.
I personally never used two different type of records within 1 message however, used simple text NDEF message it worked.
-Cheers,AA
Foreground push and dispatch have worked for me reasonably reliably with two Nexus S devices. There was an occasion when foreground dispatch fails to work. I managed to resolve the issue by simply removing the battery cover, inspect and clean the (metal) NFC antenna connection and reinstall the cover, making sure it's a snug fit.

Categories

Resources