Android deeplink path, pathPrefix or pathPattern not working - android

I am trying to make Android deeplinking work only for specific urls e.g.:
https://books.com/book/nice-title-of-a-book
https://books.com/book/abc-for-dummies
So http://books.com/about keeps linking to the webpage
This configurations in my AndroidManifest.xml works and opens the correct page in my app. The issue is that this matches every page on books.com
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="#string/custom_url_scheme" />
<data android:scheme="https" android:host="books.com" />
</intent-filter>
When I change the data part into:
<data android:scheme="https" android:host="books.com" android:path="/book/nice-book-1" />
or
<data android:scheme="https" android:host="books.com" android:pathPrefix="/book" />
or
<data android:scheme="https" android:host="books.com" android:pathPattern="/book/..*" />
to match only /book followed by a slug, it does not work a all.
I've already found many similar questions on Stackoverflow but they are either quite dated or not handle the situation where an url works with slugs.
Android Navigation Deep Link - Ignore Query
Intent filter using path,pathPrefix, or pathPattern
How to use PathPattern in order to create DeepLink Apps Android?
Does anyone have run into the same issues when matching only a few urls with slugs?

It took me a very long time to figure this out. So I'll answer my own question to save others precious time.
It turned out that when running an Android app on a device via Android studio
<data android:scheme="https" android:host="books.com" />
Is the only path that will work.
When using:
<data android:scheme="https" android:host="books.com" android:path="/book/nice-book-1" />
or
<data android:scheme="https" android:host="books.com" android:pathPrefix="/book" />
These will only work when using a SIGNED version of the app on your device. This probably because in your assetlinks.json there is a sha256_cert_fingerprints which can only be verified when a signed app is used.

Related

Deep Links and Instant Apps

I am attempting to implement deep links within my Instant App, and keep running into issues that seem to be coming from something to do with the base application. Currently, the error I'm receiving from the Play Console states:
You should have at least one active installed app APK that mapped to
site 'example.site.com' through a web intent-filter.
I do have an intent-filters set up in both the instant app and in the full base app. The intent-filters in the base application look like this:
<intent-filter>
<data
android:scheme="http"
android:host="example.site.com"
android:pathPattern="/test/app/" />
</intent-filter>
<intent-filter>
<data
android:scheme="https"
android:host="example.site.com"
android:pathPattern="/test/app/" />
</intent-filter>
And the intent-filters in the instant app module's manifest look like this:
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:scheme="https"
android:host="example.site.com"
android:pathPattern="/test/app/" />
<data
android:scheme="http"
android:host="example.site.com"
android:pathPattern="/test/app/" />
</intent-filter>
With the instant app manifest also containing a default url, set up within the activity tag.
I'm not sure what I am missing here. I have set up the intent filters as I've seen elsewhere on the web, in Google's documentation, and in other forum posts where I've seen people encountering issues with this process. I've also hosted the assetlinks.json file in the .well-known directory on my domain, and verified that it is correct and accessible using Google's verification API. Does anyone know what the issue causing this error may be? Thanks!
From what I have read in the documentation you need to make sure that you use an intent-filter with autoVerify, action and categories for the app as well. In your example you can simply copy & paste the intent-filter that you are using in the instant-app to your full app.
In case you are using string resources for scheme, host or pathPattern I would try to avoid this and directly enter your values in the manifest instead.
e.g. (crafted from your post)
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:scheme="https"
android:host="example.site.com"
android:pathPattern="/test/app/" />
<data
android:scheme="http"
android:host="example.site.com"
android:pathPattern="/test/app/" />
</intent-filter>

Intent filter works on emulator but not on device

I'm creating a custom intent filter which will open my app when I tap a file with a certain file extension (.myextension in this case.) The intent-filter is below. This currently works perfectly every time I open a .myextension file from my emulator. However, when I try it from my device, it no longer works.
On my device, when I tap a .myextension file in the Files browser app, I see Unable to preview file. instead of automatically opening the app. I've tried opening the file from quite a few locations (Files app, GDrive, Downloads folder, Slack/Gmail, both internal storage and SDCard.) I'm using Android 10 on both my emulator and my device.
<intent-filter android:label="My App">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:scheme="content"
android:mimeType="*/*"
android:host="*"
android:pathPattern=".*\\.myextension" />
</intent-filter>
I've also tried replacing that data tag/adding a second tag with this block but it doesn't seem to help:
<data
android:scheme="file"
android:mimeType="*/*"
android:host="*"
android:pathPattern=".*\\.myextension" />
Am I missing something obvious? Any help would be greatly appreciated. Thanks!
This currently works perfectly every time I open a .myextension file from my emulator.
It will fail much of the time, as it is not really tied to an emulator versus a device.
However, when I try it from my device, it no longer works.
A content Uri is not required to have a file extension, just as an https URL is not required to have a file extension. Much of the time, a content Uri will not have a file extension, and such a Uri will not match your <intent-filter>.
ACTION_VIEW is mostly for files with a widely-recognized MIME type.
I've also tried replacing that data tag/adding a second tag with this block but it doesn't seem to help
file Uri values have been generally banned since Android 7.0.
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="file" />
<data android:pathPattern=".*\\.myextension" />
<data android:pathPattern="/*.*\\.myextension" />
<data android:pathPattern="/*.*\\..*\\.myextension" />
<data android:pathPattern="/*.*\\..*\\..*\\.myextension" />
<data android:pathPattern="/*.*\\..*\\..*\\..*\\.myextension" />
<data android:pathPattern="/*.*\\..*\\..*\\..*\\..*\\.myextension" />
<data android:pathPattern="/*.*\\..*\\..*\\..*\\..*\\..*\\.myextension" />
<data android:pathPattern="/*.*\\..*\\..*\\..*\\..*\\..*\\..*\\.myextension" />
<data android:pathPattern="/*.*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.myextension" />
<data android:host="*" />
</intent-filter>
Though it doesnt work in some of the file managers Better first try in ESExplorer.

Deep linking. Is it possible to create intent filter to detect urls without https or http scheme?

I'm trying to get deep linking working in my app. I'd like to detect three url types: one with https (for example https://my-app.com), one with http (http://my-app.com) and one without any scheme (my-app.com). First two works just fine, but how to get third one working?
So far i get this code:
<intent-filter>
<data
android:host="my-app.com"
android:scheme="http" />
<data
android:host="my-app.com"
android:scheme="https" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
I tried with <data android:scheme="my-app.com" />, but no luck.
Thanks in advance for any hints.

Android: app linking - supporting only certain paths?

I want to setup app linking for my app but only for it to be active on certain paths. In other words, in my manifest:
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" android:host="www.mydomain.com/[mypath]" />
<data android:scheme="https" android:host="www.mydomain.com/[mypath]" />
</intent-filter>
I don't want every url that has my domain to open the app - they can open in the browser as usual. I only want urls that include the specific subpath to open in the app. Is this pattern allowed or is it "all or nothing" for app linking?
Link to the developer docs:
http://developer.android.com/training/app-links/index.html
You can have special paths, but you can't/shouldn't have them appended to the host.
You should have
<data android:scheme="https" android:host="www.mydomain.com" />
And from there you can use the android:path android:pathPattern or android:pathPrefix to create special patterns.
For example,
<data android:scheme="https" android:host="www.google.com" android:path="/en/index.html"/>
would only catch the url "https://www.google.com/en/index.html"

Android respond only to a Sub-URI

My App is able to respond to any link in the browser visiting example.com with the following code. My question is, how can I program my app only to respond to
"http://example.com/#push/...".
I have to implement it this way, because only if the link contains the specific path, it should be possible to open the link with my app. Not in general. Another possible solution would be to allow any URI, but that one. So my App respond to any link but one.
<intent-filter>
<data
android:host="example.com"
android:scheme="http" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<action android:name="android.intent.action.VIEW" />
</intent-filter>
I tried to add a pathPattern, but that results in not opening the link anymore:
<data
android:host="example.com"
android:pathPattern=".*push.*"
android:scheme="http" />
You should try with
<data
android:host="example.com"
android:pathPrefix="/#push/"
android:scheme="http" />
This way you can check only the initial part of the path.
Remember to include the leading / since it is a path segment.
The official documentation has a couple of examples on using the element:
http://developer.android.com/guide/topics/manifest/data-element.html

Categories

Resources