[FIXED] How to verify android app links on android 12 and higher?

Issue

Problem is opening application over link in android 12 or higher.

Everything works fine on lower versions of android.

When I look at my “App Info” -> “Open by default” screen. I see unapproved links.

When I turn on that link as approved inside supported web addresses, opening app via link works.

enter image description here

I have read about verifying intent filter inside android documentation and everything looks fine to me.

https://developer.android.com/training/app-links/verify-site-associations#add-intent-filters

Have aded .well-known/assetlinks.json to my domain
https://my.domain.net/.well-known/assetlinks.json
content of .well-known/assetlinks.json (generated and checked with https://developers.google.com/digital-asset-links/tools/generator)

[{
  "relation": ["delegate_permission/common.handle_all_urls"],
  "target" : { "namespace": "android_app", "package_name": "my.package.name",
               "sha256_cert_fingerprints": ["SHA_256"] }
}]

Triple checked that I am using correct SHA_256.

Also tested if .json is okay with “Statement List Generator and Tester”, link mentioned above.

Intent filter inside AndroidManifest.xml

<intent-filter
   android:autoVerify="true"
   android:label="@string/login_to_app">
  
   <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.domain.net"
      android:pathPrefix="/${dynamicVar}/our/application/"
      android:scheme="https" />
 </intent-filter>

Also I uploaded application to play store just to make sure this is not problem with SHA certificates or play store related, but no difference there.

Also I checked my app package name and it is correct for both internal testing and debugging.

I have also gone the way of adding every combination of app package names just to make sure.

Shortly:
Opening application via link on android 12 and higher does not work due to unsupported web addresses.

I am aware that links need to be verified with .well-known/assetlinks.json
When I manually check supported web addresses it works perfectly but that is not the end solution.

I cannot figure out what am I missing out here.

Anyone have an idea what could I be doing wrong here?

Solution

What changed?

As from Android 12 they have introduced a new way of checking for supported web domains.

Lower versions of android remain unchanged.

How does verification in android 12 works?

On installing the application android sends async requests to domains inside intent links to check if .well-known/assetlinks.json exists and is valid.

How to generate assetlinks.json?

I recommend using this tool google provides for generating that file.
It can also check if assetlinks.json is present and setup correctly.
Generator: https://developers.google.com/digital-asset-links/tools/generator

Where to get SHA-256 form?

  1. Open Android Studio
  2. Open your Project
  3. Click on Gradle (From Right Side Panel, you will see Gradle Bar)
  4. Click on Refresh (Click on Refresh from Gradle Bar, you will see List
  5. Gradle scripts of your Project)
  6. Click on Your Project (Your Project Name form List (root))
  7. Click on Tasks
  8. Click on Android
  9. Double Click on signingReport (You will get SHA1 and MD5 in Run
    Bar(Sometimes it will be in Gradle Console))
  10. Select app module from module selection dropdown to run or debug your application

After you have generated .json file, at put it inside root of domain (.well-known/assetlinks.json).
I recommend opening it manually just to make sure.
https://my.domain.com/.well-known/assetlinks.json

Setting up Intent links in application

To you AndroidManifest.xml add

<!-- Make sure you explicitly set android:autoVerify to "true". -->
  <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" />

    <!-- If a user clicks on a shared link that uses the "http" scheme, your
         app should be able to delegate that traffic to "https". -->
    <data android:scheme="http" />
    <data android:scheme="https" />

    <!-- Include one or more domains that should be verified. -->
      <data
              android:scheme="https"
              android:host="**my.domain.com**"
              android:pathPrefix="/test" />
  </intent-filter>

Manually test if intent link is working:

You can run this command with your emulator running and it should open the application:

adb shell am start -W -a android.intent.action.VIEW -d "https://my.domain.com/test?code=abcde"

Manually test intent link

  1. Support the updated domain verification process
  • adb shell am compat enable 175408749 PACKAGE_NAME
  1. Reset the state of Android App Links on a device
  • adb shell pm set-app-links --package PACKAGE_NAME 0 all
  1. Invoke the domain verification process
  • adb shell pm verify-app-links --re-verify PACKAGE_NAME
    After running this command, it is CRUCIAL to wait for at least a minute for app to verify your domain.
  1. Review the verification results
  • adb shell pm get-app-links PACKAGE_NAME

The output of this command is similar to the following:

com.example.pkg:
    ID: 01234567-89ab-cdef-0123-456789abcdef
    Signatures: [***]
    Domain verification state:
      my.domain.com: verified
      sub.example.com: legacy_failure
      example.net: verified
      example.org: 1026

After that you’re good to go, your intent links will work on android 12 and lower.

Final test to check if you have set up everything properly
Run:

adb shell am start -W -a android.intent.action.VIEW -d "https://my.domain.com/test?code=abcde"

Source: https://developer.android.com/training/app-links/verify-site-associations

Answered By – Tomislav Lazar

Answer Checked By – Mildred Charles (Easybugfix Admin)

Leave a Reply

(*) Required, Your email will not be published