androidreact-nativeurlnext.js

Android deep linking not working with assetlinks.json


I am trying to implement deep linking to my android app.

This is my AndroidManifest with the intent-filters:

<manifest xmlns:android="http://schemas.android.com/apk/res/android">
  <uses-permission android:name="android.permission.INTERNET" />
  <uses-permission android:name="android.permission.VIBRATE" />
  <application android:usesCleartextTraffic="true" android:name=".MainApplication"
    android:label="@string/app_name" android:icon="@mipmap/ic_launcher"
    android:roundIcon="@mipmap/ic_launcher_round" android:allowBackup="false"
    android:theme="@style/AppTheme" android:screenOrientation="portrait">
    <activity android:name=".MainActivity" android:label="@string/app_name"
      android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"
      android:launchMode="singleTask" android:windowSoftInputMode="adjustResize"
      android:exported="true">
      <intent-filter android:autoVerify="true">
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
      <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="mygainplan" />
      </intent-filter>
      <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="http" />
        <data android:scheme="https" />
        <data android:host="www.my-gainplan.com" />
        <data android:pathPrefix="/workouts" />
      </intent-filter>
    </activity>
  </application>
</manifest>

I am using react-navigation for handling deep links inside my app with this config

const linking = {
  prefixes: [
    'https://www.my-gainplan.com',
    'mygainplan://',
    'https://my-gainplan.com',
  ],
  config: {
    screens: {
      MyWorkouts: 'workouts',
    },
  },
};

To make this work with my website, I have added the following assetlinks.json to my website

[
  {
    "relation": ["delegate_permission/common.handle_all_urls"],
    "target": {
      "namespace": "android_app",
      "package_name": "com.mygainplan",
      "sha256_cert_fingerprints": [
        "FA:C6:17:45:DC:09:03:78:6F:B9:ED:E6:2A:96:2B:39:9F:73:48:F0:BB:6F:89:9B:83:32:66:75:91:03:3B:9C"
      ]
    }
  }
]

The sha256 is the one from the android debug keystore.

When I run the app in debug mode, links with the prefix mygainplan:// work just fine, but links from the website (https://www.my-gainplan.com/workouts) just open the web browser and not the app. Why is this happening?


Solution

  • I had to add android:autoVerify="true" to the intent filter that specifies the domain aswell. With that added, the deep link works just fine