Instant Apps with NFC
Asked Answered
D

1

16

I'm trying to get an instant app to be opened via NFC.

I have something like the below in my AndroidManifest.xml

<intent-filter android:autoVerify="true">
    <action android:name="android.intent.action.VIEW" />
    <action android:name="android.nfc.action.NDEF_DISCOVERED" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />

    <data android:scheme="https" />
    <data android:scheme="http" />
    <data android:host="example-refresh.herokuapp.com" />
</intent-filter>

When going to https://example-refresh.herokuapp.com (example link obviously) from a link click the instant app loads correctly. When opening that link from an nfc tag the browser just loads. I've tried also having the nfc open an AAR (https://developer.android.com/guide/topics/connectivity/nfc/nfc.html#aar) this results in the play store link opening when the app isn't installed and the app correctly opening from the nfc when it is installed. If I have something else on the nfc so it shows the disambigious options then I can select instant app for the browser option, but I would like for it to default to instant app.

Is there something I'm missing to get an nfc tag to load an instant app? I've also tried using branch, but with no luck.

Denver answered 26/10, 2017 at 7:50 Comment(15)
If i understand correctly, this link can help you #44325941Endocrinology
Thanks for the link, unfortunately, it isn't too helpful. The answer suggests "If you want to trigger your Instant App when a NFC tag is tapped, that should work if you tie an Instant App-enabled URL to a tag." That is the setup I currently have except that the nfc opens the browser instead of the instant app.Denver
The point of the linked answer is that when the NFC is tapped, the device will try to resolve the URL and that should point it towards the instant app. There should be no disambiguation dialog. I tested by faking a NFC URL tag on a N device, and it opened my instant app (and installed app) with the same intent-filter like yours. (https://mcmap.net/q/428298/-how-to-simulate-the-tag-touch-from-other-application)Endocrinology
Thanks Pragati. This helped me narrow in a bit, on my test device (a pixel running O) a non-url formatted NFC intent opened the app fine. A url formatted NFC intent (eg. example-refresh.herokuapp.com) opened chrome with no disambiguation dialog. When I disabled chrome the same url formatted intent opened my app. This makes me think that chrome is hijacking NFC intents that look like browser in such a way that doesn't trigger instant apps on some devices. Do you have a link to your device I could put on an NFC to see if it is my device?Denver
Just to make sure, have you placed an assetlinks.json file in your server?Despatch
Yep, and if I click on the link app links and instant apps work. It's just opening from nfc that doesn't work. I don't believe there is anything special on the asstlinks file I need to change to support nfc.Denver
You can try testing with buzzfeed.com/nifty This link opened an AIA for me with faking the nfc tag.Ionosphere
Actually, I had already tried buzzfeed.com/tasty with no luck on the mocked NFC (opened the web page). I thought that might be because they don't handle NFC, but if it works for you that makes me think there is something specific to my device. I'll give a try on some other devices and see what happens. Thanks for the help.Denver
I suspect that your device's Chrome browser has overridden some opening-link defaults, have you tried to "Clear Data" on Chrome (as well as any other browser app)?Ionosphere
@RyanC Many apps will filter for ACTION_NDEF_DISCOVERED or ACTION_TECH_DISCOVERED before ACTION_TAG_DISCOVERED, so your apps have a low probability of starting. ACTION_TAG_DISCOVERED is only available as a last resort for apps to filter for in the cases where no other apps are installed to handle the ACTION_NDEF_DISCOVERED or ACTION_TECH_DISCOVERED intent.Undershrub
@RyanC I got my hands on an O device and found out it does not work (the same test I used on a N device), this could explain the issue you're having (you mentioned you were on O). I would suggest filing a bug to issuetracker.google.com/issues/… and link it back here too.Ionosphere
Reported: issuetracker.google.com/u/1/issues/69368203Denver
Reproduced the same issue, will star your link!Swetiana
@RyanC have you done it? because I still have problems with it ..Mod
@RyanC in my case, even disabling chrome didn't help. It will vibrate knowing it picked something up, but won't open the IA. Where you able to open the IA through NFC with a newer phone? Also, are we assuming that manifest contains ACTION_NDEF_DISCOVERED?Gwenore
D
1

Instant apps have a very limited set of allowed permissions and NFC is not in that set. Thus any NFC related intent will not work. Besides, whatever you define on your manifest only works when your app is installed. Which obviously is not the case for instant apps. Google does index the android.intent.action.VIEW intents when you upload your APK to Play Store, so they can make instant app works.

So when you scan an NFC, it is an android.nfc.action.NDEF_DISCOVERED intent, and therefore your app won't be launched

However, you still can make it work. Instead of using the link you would normally use to launch your instant app, you should write the link to your instant app on the Play Store to your NFC tag.

https://play.google.com/store/apps/details?id=<package_name>&launch=true

Check https://developer.android.com/distribute/marketing-tools/linking-to-google-play#Instant

Duvalier answered 1/10, 2020 at 17:36 Comment(3)
Does the NFC Intent then make it into the started instant app, so the NFC tag can be read and written or is this only usable for starting the instant app?Pentadactyl
What to do if the NFC needs to work for both iOS and Android?Pitchman
@Pentadactyl it is sent to the Play Store app which will launch the instant app.Inverter

© 2022 - 2024 — McMap. All rights reserved.