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

Android 13下Jetpack Compose导航深度链接无法跳转问题

解决Jetpack Compose+Navigation深度链接无法唤起应用的问题

核心问题排查与修复

1. 完成数字资产链接验证(必做,因设置了autoVerify="true")

当Intent Filter中添加android:autoVerify="true"时,系统要求域名必须通过Digital Asset Links验证,证明域名授权你的应用处理链接:

  • 在域名下创建.well-known/assetlinks.json文件,替换占位符为实际信息:
[{
  "relation": ["delegate_permission/common.handle_all_urls"],
  "target": {
    "namespace": "android_app",
    "package_name": "你的应用包名",
    "sha256_cert_fingerprints": ["你的应用签名SHA-256指纹"]
  }
}]
  • 获取SHA-256指纹:可通过Android Studio的Build > Generate Signed Bundle/APK流程查看,或用命令行:
    keytool -list -v -keystore 你的签名文件路径.jks -alias 你的签名别名
    
  • 确保文件能通过https://gymsaround.example.com/.well-known/assetlinks.json正常访问,且返回的Content-Type为application/json。

2. 修正Intent Filter配置

  • 确认Intent Filter添加在承载NavHost的Activity(通常是MainActivity)上,而非其他Activity。
  • 给<data>标签补充pathPrefix,精准匹配深度链接路径,避免捕获域名下所有链接:
<data
    android:host="gymsaround.example.com"
    android:scheme="https"
    android:pathPrefix="/details" />

3. 验证应用端深度链接逻辑

用ADB命令直接测试,排除Chrome缓存或配置干扰:

adb shell am start -a android.intent.action.VIEW -d "https://gymsaround.example.com/details/123"

如果命令能唤起应用并跳转到GymDetailsScreen,说明应用端配置无问题,此时可清除Chrome数据或用隐私模式重试。

在承载NavHost的代码中,必须让NavController处理Intent中的DeepLink:
Compose环境下:

val navController = rememberNavController()
val intent = LocalContext.current.intent
LaunchedEffect(intent) {
    navController.handleDeepLink(intent)
}

NavHost(navController = navController, startDestination = "home") {
    // 你的Composable路由配置
}

Activity的onCreate方法中:

val navController = findNavController(R.id.nav_host_fragment)
navController.handleDeepLink(intent)

关键提示

大部分Chrome不唤起应用的情况,都是因为数字资产链接验证失败,导致autoVerify不生效,系统直接打开网页。优先排查这一步,再逐步验证其他配置。

内容的提问来源于stack exchange,提问作者Ali El-Sayed

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.25 04:22:50