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

Compose Navigation带查询参数的Intent Filter匹配失败问题

问题排查与解决方案

针对你遇到的深度链接匹配失败问题,可按以下步骤逐一排查:

1. 修复ADB命令的Shell转义问题

直接执行adb shell am start -d https://my-website.com/venue?id=123时,Shell会将?解析为通配符,导致实际传递给系统的URI不完整。需给URL添加引号避免解析错误:

adb shell am start -d "https://my-website.com/venue?id=123"

2. 检查Activity的exported属性

Android 12及以上版本要求可被外部启动的Activity必须显式设置android:exported="true",否则系统无法匹配到该Activity。确保你的Activity配置包含:

<activity
    android:name=".YourDeepLinkActivity"
    android:exported="true">
    <!-- 你的Intent Filter配置 -->
</activity>

3. 优化Intent Filter的Data配置

原配置中多个<data>标签的组合逻辑易产生误解,建议拆分明确匹配HTTP和HTTPS协议的完整URI规则,避免系统匹配逻辑混乱:

<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" />
    
    <!-- 匹配HTTP协议的链接 -->
    <data
        android:scheme="http"
        android:host="my-website.com"
        android:path="/venue" />
    
    <!-- 匹配HTTPS协议的链接 -->
    <data
        android:scheme="https"
        android:host="my-website.com"
        android:path="/venue" />
</intent-filter>

4. 完善导航组件的DeepLink配置

在导航组件的navDeepLink中补充对应的Action和Category,与Intent Filter完全对齐,确保内部路由匹配无遗漏:

private const val venueDetailsNavigationRoute = "venue_details"
private const val venueIdArg = "venueId"

composable(
    route = "$venueDetailsNavigationRoute/{$venueIdArg}",
    deepLinks = listOf(
        navDeepLink {
            uriPattern = "https://my-website.com/venue?id={$venueIdArg}"
            action = Intent.ACTION_VIEW
            categories = setOf(Intent.CATEGORY_DEFAULT, Intent.CATEGORY_BROWSABLE)
        }
    ),
    arguments = listOf(
        navArgument(venueIdArg) { type = NavType.StringType }
    )
) { backStackEntry ->
    val venueId = backStackEntry.arguments?.getString(venueIdArg)
    // 页面逻辑实现
}

5. 辅助测试验证

  • 使用Android Studio的App Links Assistant工具(Tools → App Links Assistant)进行深度链接测试,可直观查看匹配结果和路由跳转情况。
  • 执行带Action参数的ADB命令强制指定启动逻辑:
    adb shell am start -a android.intent.action.VIEW -d "https://my-website.com/venue?id=123"
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.12 17:05:33