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.

hata
  • 8,429
  • 5
  • 32
  • 57
Ryan C
  • 953
  • 1
  • 11
  • 26
  • If i understand correctly, this link can help you https://stackoverflow.com/questions/44325441/how-to-implement-google-instant-app-with-nfc-in-android-studio – Prags Oct 30 '17 at 04:37
  • 1
    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 Oct 30 '17 at 20:32
  • 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://stackoverflow.com/a/30908559/6668797) – Prags Nov 09 '17 at 05:07
  • 1
    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. https://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 Nov 10 '17 at 09:10
  • Just to make sure, have you placed an assetlinks.json file in your server? – Mustafa Berkay Mutlu Nov 11 '17 at 16:05
  • 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. – Ryan C Nov 11 '17 at 18:31
  • You can try testing with https://www.buzzfeed.com/nifty This link opened an AIA for me with faking the nfc tag. – TWL Nov 13 '17 at 20:18
  • 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. – Ryan C Nov 13 '17 at 21:49
  • 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)? – TWL Nov 13 '17 at 22:23
  • @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. – PN10 Nov 14 '17 at 11:48
  • @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 https://issuetracker.google.com/issues/new?component=316045&template=1018787 and link it back here too. – TWL Nov 15 '17 at 16:50
  • Reported: https://issuetracker.google.com/u/1/issues/69368203 – Ryan C Nov 22 '17 at 17:28
  • 2
    Reproduced the same issue, will star your link! – Evan Nov 28 '17 at 19:46
  • @RyanC have you done it? because I still have problems with it .. – Stonek Jan 19 '18 at 13:16
  • @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? – Jacobo Koenig Oct 15 '20 at 21:16

1 Answers1

0

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

André Oriani
  • 3,183
  • 18
  • 27