简体   繁体   中英

Android app link not working in android 12 always opening in browser

I have hosted assetlinks file into our domain https://ourdomain/.well-known/assetlinks.json And also verified this using https://developers.google.com/digital-asset-links/tools/generator and from android studio's App Links Assitant and got verified status from both the ways. But when i am sharing debug APK for testing it's always opening in browser. I also tried uploading on app store and downloaded from there for testing but it always open in browser.

Note: for debug build used my laptop SHA-256 and once app live on play store changed SHA ( got SHA-256from By going to Application Dashboard in Play Console then Release Management --> App Signing ) on hosted assetlinks file into our domain https://ourdomain/.well-known/assetlinks.json

Below is the code used in the 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="https"
                android:host="abc.test.com" />
        </intent-filter>

I have same problem and solved by going to app info setting -> set as default ->support web addresses and you will see your short link so turn it on and it will work;)

Update:

as every one said its not a programmatically way so the best way is that link below said

Deep-links are working in Android 11 or before but on Android 12 it isn't.

But even after adding assetlinks.json file and adding all the intent-filters . Android 12 still isn't detecting deep-links . In Android-Manifest file turns out that scheme's tag is need to be separated from the data tag like this:

// OLD - Which is only working Android 11 or before

<data
  android:host="domain.name"
  android:pathPrefix="/videos"
  android:scheme="https" />

// NEW - Which is working on all including Android 12

<data android:scheme="https" />
<data
    android:host="domain.name"
    android:pathPrefix="/videos" />

In my case, the app is working in android 11, but it doesn't work in android 12 when the app is compiled and built with android studio.

I tested the production app; it works fine with the app link.

For development build, I have to go to App info -> Open by default -> Add link -> check off all the available links

This seems only happen with development builds; the apps installed from Google app store automatically has all the links selected.

After adding assetlinks.json in domain you have to reinstall app (just uninstall the app and install again) that will work

In my case problem was with inconsistent between SHA Signatures in store build and https://ourdomain/.well-known/assetlinks.json, that's why deep links were disabled by default on Android 12, for fixing it we can connect our phone with problem build to Android studio and run this command:

adb shell pm get-app-links com.your_app_package_name

as a result you should see something like this:

com.your_app_package_name:
ID: .....
Signatures: [AB:CD:EF:HI:GK...]
Domain verification state:
   your_domain.com legacy_failure

next you need to check whether the signature fingerprints is included in your https://ourdomain/.well-known/assetlinks.json, in my case it doesn't, also keep in mind that in assetlinks.json file can be couple of signatures for example for debug, alpha, beta and production builds, it should looks like below:

[
  {
   "relation": ["delegate_permission/common.handle_all_urls"],
    "target": {
     "namespace": "android_app",
     "package_name": "com.your_app_package_name",
     "sha256_cert_fingerprints" :["DE:BU:GS:HA:25:6...","PR:OD:SH:A:25:6..."]
        }
    }
]

This approach should solve deeplink issue on android 12 above

Automatic approach

skip step 1 & 2

Go to Tools/ App Link Assistance and follow the step on the image

在此处输入图像描述

Manual Approach

Step 1: update all intent filters that can respond to an HTTP link with the android:autoVerify="true"

<activity
android:name="com.example.MainActivity">
    <intent-filter android:autoVerify="true">

    </intent-filter>
</activity>

Step 2: Create the assetlinks.json file and update your package and sha key

  //update package_name and sha256_cert_fingerprints with yours
[{
  "relation": ["delegate_permission/common.handle_all_urls"],
  "target": {
  "namespace": "android_app",
  "package_name": "Your App’s package name", 
  "sha256_cert_fingerprints":  ["Your App’s SHA256 finger print"]
 }

}]

Step 3: Publishing the JSON verification file Work with your infrastructure team to deploy the assetlinks.json file to the host

https://your domain.com/.well-known/assetlinks.json

Be sure of the following:

  • The assetlinks.json file is served with content-type application/json.
  • The assetlinks.json file must be accessible over an HTTPS connection, regardless of whether your app's intent filters declare HTTPS as the data scheme.
  • The assetlinks.json file must be accessible without any redirects (no 301 or 302 redirects).
  • Do not publish your app with dev/test URLs in the manifest file that may not be accessible to the public (such as any that are accessible only with a VPN). A work-around in such cases is to configure build variants to generate a different manifest file for dev builds.

This fixed it for me:

<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:host="my.page.link"  />
    <data android:scheme="https" />
        
</intent-filter>

Notice: android:autoVerify="true"

The weird thing about this is only broke on certain Android phones, and wasn't necessarily consistent across API versions. Pixel 4 on API 33 worked fine without this fix and didn't work with Pixel 6 on API 33. What can ya do.

In my case after doing the above (debug/release SHA-256 keys in assetlinks, separate the scheme tag) the final culprit turned out to be the "path" tag. For some reason the verification process does not include the tag even though this has always been there in the app and used to work prior to Android 12. Not a big deal in my app since I was ignoring the path anyway.

Before (not working):

<data android:host="dl.example.com"
      android:path="/test" />
<data android:scheme="https" />

After (working):

<data android:host="dl.example.com"/>
<data android:scheme="https"/>

Hope it helps someone

Follow these steps:

Step 1:

Add android:autoVerify="true" to your intents-filter.

Step 2:

Move the android:scheme to separate data tag

So now your intents-filter in manifest looks 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:host="websiteUrl"
        android:pathPrefix="/" />
    <data
        android:scheme="https" />
    <!-- note that the leading "/" is required for pathPrefix-->
</intent-filter>

Step 3:

Add your Digital Asset Links JSON file to following url:

https://{yourdomain.name}/.well-known/assetlinks.json

Note :- For production app make sure you use the digital asset links JSON file generated by Play console. You can find it at

Play console -> Your App -> Setup (Side menu option) -> App Integrity -> App signing (scroll to the bottom)

Step 4:

Verify that all the steps are correctly implemented by manually running app link validation using these commands - https://developer.android.com/training/app-links/verify-android-applinks#manual-verification

Step 5:

If your links were shown as verified in step 4 then now install the app on device and wait for atleast 2-3 minutes before clicking on any app links because in this time Android will verify your app links by reading your manifest file and the digital assets JSON file that you uploaded on your website.

After you have waited 2-3 minutes, now you can click on your app link and it should open your app.

Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM