There are a ton of examples on SE on how to do this, but I can't seem to get it to work. What I want to do is when a tag with a dev.example.com is scanned, either my app is launched, if installed, or if not installed, just go to the URL in the tag. This should happen whether the app is running or not.
In the manifest :
<activity android:name=".MainActivity">
<intent-filter android:label="@string/app_name">
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:host="dev.example.com"
android:scheme="https" />
</intent-filter>
I have an NFC tag with https://dev.example.com written to the first NDEF record.
No matter what I do, if I scan it with my S7, it pops up
NFC Request
You are being requested to open a web address tag (https://dev.example.com)
[] Dont ask me about nfc again
cancel ok
(I never click "dont ask me again") Clicking OK launches the default browser.
If I change the manifest to filter on plaintext NDEF..
<intent-filter android:label="@string/app_name">
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
And I write a text NDEF record, my app does launch.
SO why is the URL not working?
I have also tried adding
android:pathPrefix="/app"
to the url intent and written https://dev.example.com/app to the tag. Still my app does not intercept any URL NDEF records.
Also I have a
protected void onNewIntent(Intent intent) {}
in my main activity but it never gets called, even when the text NDEF launches the app. But one issue at a time..
I don't really have any other phones to try it on. I tried on another S7 and it just launched the URL regardless if the app was installed or not. (He probably checked "dont ask again")
Thanks.