Android中android:path类型DeepLink无法跳转App,直接打开浏览器问题
React Native Android DeepLink 精确路径无法跳转问题解决
问题分析
你遇到的情况是:配置了android:path="/reader/all"的精确匹配DeepLink无法触发应用跳转,直接在浏览器打开,但android:pathPrefix类型的链接正常工作。核心原因可能有两个:
- 同一个
intent-filter内混合使用path和pathPrefix时,自动验证(autoVerify)的规则冲突:当开启android:autoVerify="true"时,该过滤器下的所有DeepLink都需要通过Digital Asset Links验证,若你的网站assetlinks.json未包含精确路径/reader/all的授权,系统会拒绝应用处理该链接。 - 链接匹配的精确性:如果测试链接带有末尾斜杠(如
https://www.xyz.com/reader/all/),path="/reader/all"会因不匹配而失效,而pathPrefix会正常匹配。
解决方案
1. 拆分Intent Filter,单独验证精确路径
将精确匹配的DeepLink单独放在一个intent-filter中,避免和前缀匹配规则相互干扰,同时确保每个过滤器都开启自动验证:
修改后的AndroidManifest.xml关键部分:
<activity android:name=".MainActivity" android:label="@string/app_name" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode" android:launchMode="singleTask" android:screenOrientation="portrait" android:windowSoftInputMode="adjustResize" android:exported="true"> <!-- 启动页过滤器 --> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> <!-- 单独处理精确路径 /reader/all --> <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="www.xyz.com" android:path="/reader/all"/> </intent-filter> <!-- 处理所有前缀匹配的DeepLink --> <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="www.xyz.com" android:pathPrefix="/reader/settings/digest"/> <data android:scheme="https" android:host="www.xyz.com" android:pathPrefix="/reader/fo"/> <data android:scheme="https" android:host="www.xyz.com" android:pathPrefix="/reader/fe"/> </intent-filter> </activity>
2. 检查Digital Asset Links配置
确保你的网站https://www.xyz.com/.well-known/assetlinks.json文件包含对应用的授权,若要覆盖所有路径,配置示例如下(替换为你的应用包名和证书指纹):
[{ "relation": ["delegate_permission/common.handle_all_urls"], "target": { "namespace": "android_app", "package_name": "com.your.app.package", "sha256_cert_fingerprints": ["AB:CD:EF...你的SHA256指纹"] } }]
3. 验证测试链接的精确性
确保测试链接完全匹配https://www.xyz.com/reader/all:
- 不要带有末尾斜杠(
/reader/all/) - 若链接包含查询参数(如
?id=1),android:path仍会匹配路径部分,无需修改配置
4. 清除应用默认打开设置
如果之前误选了浏览器打开该链接,系统会记住默认选项:
- 进入手机设置 → 应用 → 找到你的应用
- 选择“默认打开方式” → 清除默认设置
- 重新测试DeepLink
内容的提问来源于stack exchange,提问作者Arpit Mishra
相关产品推荐
相关产品推荐

