我正在尝试实现到我的 Android 应用程序的深度链接。
这是我的带有意图过滤器的 AndroidManifest:
<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>
我正在使用反应导航来通过此配置处理我的应用程序内的深层链接
const linking = {
prefixes: [
'https://www.my-gainplan.com',
'mygainplan://',
'https://my-gainplan.com',
],
config: {
screens: {
MyWorkouts: 'workouts',
},
},
};
为了使此功能适用于我的网站,我已将以下 assetlinks.json 添加到我的网站
[
{
"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"
]
}
}
]
sha256 是来自 android 调试密钥库的。
当我在调试模式下运行应用程序时,带有前缀 mygainplan:// 的链接工作得很好,但来自网站 (https://www.my-gainplan.com/workouts) 的链接只需打开 Web 浏览器并不是应用程序。为什么会出现这种情况?
我必须将 android:autoVerify="true" 添加到指定域的意图过滤器中。添加后,深层链接就可以正常工作了