16
votes

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.

1
If i understand correctly, this link can help you stackoverflow.com/questions/44325441/…Prags
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.Ryan C
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. (stackoverflow.com/a/30908559/6668797)Prags
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?Ryan C
Reproduced the same issue, will star your link!Evan

1 Answers

1
votes

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