Reputation: 99
I want to use Deep links in my app using Jetpack Compose and Jetpack navigation. I try to open the app using the link from google chrome but the app isn't opened and google chrome handle the request as if it is a regular website link.
I Tried to Use Deep linking with Jetpack Compose I did the following
composable(
route = "gyms/{gym_id}",
arguments = listOf(navArgument(name = "gym_id") { type = NavType.IntType }),
deepLinks = listOf(navDeepLink {
uriPattern = "https://gymsaround.example.com/details/{gym_id}"
action = Intent.ACTION_VIEW
})
) { GymDetailsScreen() }
<intent-filter android:autoVerify="true">
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<action android:name="android.intent.action.VIEW" />
<data
android:host="gymsaround.example.com"
android:scheme="https" />
</intent-filter>
Upvotes: 9
Views: 15527
Reputation: 383
First, you should add this intent filter tag in your manifest file:
<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="YourWebSite.com" />
<data
android:scheme="https"
android:host="YourWebSite.com" />
<data
android:host="open.my.app.example.com" />
</intent-filter>
You should also add this piece of code to your manifest if you are working on a flutter application:
<meta-data android:name="flutter_deeplinking_enabled" android:value="true" />
This is enough for Android below version 13 and works perfectly.
However, Android 13 and above differentiate between verified and non-verified deep links. If you have a verified link, it opens automatically. To verify your link, you should add an assetlinks.json
file in the .well-known
folder of your website. The assetlinks.json should contain a JSON object like this:
[
{
"relation": [
"delegate_permission/common.handle_all_urls"
],
"target": {
"namespace": "android_app",
"package_name": "YOUR_APP_PACKAGE_NAME",
"sha256_cert_fingerprints": [
"YOUR_SHA256_RELEASE",
"YOUR_SHA256_DEBUG (optional, to enable deep links in debug mode)"
]
}
}
]
With a verified deep link, your application will open automatically.
If you don't have a verified link, for example, a sample link like open.my.app.example.com
which isn't a real website, your user needs to follow these steps:
Now your application has permission to open these types of links.
Upvotes: 3
Reputation: 669
Set the 2 sha256_cert_fingerprints one gets from your keystore file and another from the Google Play console App signing key certificate. upload both to the https://yourdomain.example.com/.well-known/assetlinks.json like as below
[
{
"relation": ["delegate_permission/common.handle_all_urls"],
"target": {
"namespace": "android_app",
"package_name": "com.example.android",
"sha256_cert_fingerprints": [
"SH:A2:56:FR:OM:PL:AY:CO:NS:OL:EX:......"
]
}
},
{
"relation": ["delegate_permission/common.handle_all_urls"],
"target": {
"namespace": "android_app",
"package_name": "com.example.android",
"sha256_cert_fingerprints": [
"SH:A2:56:FR:OM:AN:DR:OI:DS:TU:DI:OO......"
]
}
}]
also, set AndroidManifest.xml like below
<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" />
<data android:scheme="https" />
<data android:host="yourdomain.example.com" />
</intent-filter>
Upvotes: 1
Reputation: 19263
looks like you are mixing Deep Linking with App Linking. Have you placed assetlinks.json
file in proper path (under proper url)?
https://gymsaround.example.com/.well-known/assetlinks.json
as you have android:autoVerify="true"
- this line makes Android check that domain is confirming that app can handle URL without opening web (browser app), some more doc in HERE. if yes then app will automatically be opened without any prompt for user, if not still web page will be shown (as in your case) - this is App Linking
in short this gives no asking user for picking any app, your app will be picked (if verified), one step less, and cutting out option for picking "always" for web browser
if you just want to ask user at first click if he want to open URL in (your) app or in web browser then remove autoVerify
flag, it's not part of Deep Linking and unneccessary always-failed domain check may probably break even picking option (marked as "untrusted app" or similar...)
Upvotes: 1