You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android Deep Link跳转Chrome而非目标应用,求问题排查方案

Deep Link唤起应用失败跳转Chrome的问题排查与解决

问题描述

学习Android Deep Link配置,已为MainActivity添加intent-filter,并在onCreate中调用参数获取函数,但执行adb命令:

./adb shell am start -W -a android.intent.action.VIEW -d "https://courseapp.com/guides?id=123"

后,链接打开的是Chrome浏览器而非目标MainActivity,adb返回结果:

Status: ok LaunchState: UNKNOWN (0) Activity: com.android.chrome/org.chromium.chrome.browser.document.ChromeLauncherActivity WaitTime: 139 Complete

配置的intent-filter代码:

<activity
    android:name=".main.MainActivity"
    android:exported="true"
    android:launchMode="singleTask"
    android:label="@string/app_name" >
    <tools:validation testUrl="https://courseapp.com/guide" />

    <intent-filter android:autoVerify="true" android:label="@string/app_name">
        <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="courseapp.com"/>
    </intent-filter>
    <intent-filter android:autoVerify="true" android:label="@string/app_name">
        <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"
            android:host="courseapp.com"/>
    </intent-filter>
    <intent-filter android:autoVerify="true" android:label="@string/app_name">
        <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"
            android:host="courseapp.com"
            android:pathPrefix="/guides"/>
    </intent-filter>
    <intent-filter android:autoVerify="true" android:label="@string/app_name">
        <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="courseapp.com"
            android:pathPrefix="/guides"/>
    </intent-filter>

</activity>

参数获取函数:

private fun getDeepLinkParamsAndRoute() {
    val data: Uri? = intent?.data
    if (data != null) {
        val parameters: List<String> = data.pathSegments
        val params = parameters[parameters.size - 1]
        Log.i("MainActivity*********Deep Link", params)
    }
}

问题原因

  1. App Link验证未完成:配置中android:autoVerify="true"会触发Android App Link验证机制,只有当域名下存在合法的assetlinks.json文件、完成应用与域名的关联验证后,系统才会直接唤起应用;未通过验证时,链接会默认跳转至浏览器。
  2. intent-filter冗余且匹配校验偏差:将scheme、host、pathPrefix拆分为多个独立intent-filter,可能导致匹配逻辑出现偏差;同时tools:validation的testUrl为https://courseapp.com/guide,与测试链接https://courseapp.com/guides不匹配,编译时无法有效验证配置正确性。

解决方案

1. 临时验证配置有效性

先移除所有intent-filter中的android:autoVerify="true"属性,重新安装应用后执行adb命令测试。若能正常唤起应用,即可确认是App Link验证问题。

2. 完成App Link验证(如需保留直接唤起功能)

在域名的https://courseapp.com/.well-known/路径下放置assetlinks.json文件,内容需包含应用包名和签名证书的SHA-256指纹:

[{
  "relation": ["delegate_permission/common.handle_all_urls"],
  "target": {
    "namespace": "android_app",
    "package_name": "你的应用包名",
    "sha256_cert_fingerprints": ["你的签名证书SHA-256指纹"]
  }
}]

也可通过Android Studio的App Links Assistant工具自动生成并上传该文件,简化验证流程。

3. 优化intent-filter配置

合并冗余的intent-filter,用多个<data>标签整合匹配规则,减少配置错误:

<activity
    android:name=".main.MainActivity"
    android:exported="true"
    android:launchMode="singleTask"
    android:label="@string/app_name" >
    <tools:validation testUrl="https://courseapp.com/guides?id=123" />

    <intent-filter android:autoVerify="true" android:label="@string/app_name">
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <!-- 匹配http/https的courseapp.com根路径 -->
        <data android:scheme="https" android:host="courseapp.com" />
        <data android:scheme="http" android:host="courseapp.com" />
        <!-- 匹配http/https的courseapp.com/guides路径 -->
        <data android:scheme="https" android:host="courseapp.com" android:pathPrefix="/guides" />
        <data android:scheme="http" android:host="courseapp.com" android:pathPrefix="/guides" />
    </intent-filter>
</activity>

4. 强制唤起测试

执行adb命令时添加-p参数指定应用包名,强制唤起应用,验证配置逻辑:

./adb shell am start -W -a android.intent.action.VIEW -d "https://courseapp.com/guides?id=123" -p 你的应用包名

内容的提问来源于stack exchange,提问作者karu6500

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.27 08:54:57