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

Android URL模式匹配:如何让Instant App捕获指定链接并忽略其余

配置Instant App仅捕获指定URL的解决方案

嘿,我明白你想要让Instant App只捕获特定的登录链接、忽略其他所有URL的需求,咱们直接来搞定正确的匹配规则配置!

核心思路

你需要在AndroidManifest.xml的<intent-filter>里精准定义URL匹配规则,只针对https://www.example.com/myuser/login/开头(包含后续任意参数)的链接进行捕获。关键是用pathPrefix锁定路径前缀,不用纠结后面的可变参数。

完整配置代码

把这段配置放到你的Instant App模块的Manifest文件中(对应处理登录的Activity的<intent-filter>里):

<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" />
    
    <!-- 仅匹配以https://www.example.com/myuser/login/开头的链接 -->
    <data
        android:scheme="https"
        android:host="www.example.com"
        android:pathPrefix="/myuser/login/" />
</intent-filter>

配置细节解释

  • android:scheme="https":限定只捕获HTTPS协议的链接,和你给出的示例URL协议一致。
  • android:host="www.example.com":锁定目标域名,确保只有这个域名下的链接才会被处理。
  • android:pathPrefix="/myuser/login/":这是核心配置!它会匹配所有路径以/myuser/login/开头的URL,不管后面跟着?tc=...、&next=...这类可变参数,完美覆盖你提供的示例链接。
  • android:autoVerify="true":可选配置,开启后系统会自动验证你的域名与App的关联,避免用户手动确认,提升使用体验。

快速测试技巧

配置完成后,可以用adb命令快速验证是否生效:

adb shell am start -a android.intent.action.VIEW -d "https://www.example.com/myuser/login/?tc=AAAAAAQXDQAUFZNUUFWSFNNVE4=&next=/myuser/foo/some-other-parameter/foo1/593567297/&utm_source=gmail.com&utm_medium=email&etm_content=58475999468525d9bb3c365c840be5%7C%7C2018-05-02T00:25:26.381895%7CpdghXgghttX0G2iKafySwUTiIrLegggSqMfid/h3IDLrYmPnI38=%7C&utm_campaign=Custom" com.your.instant.app.package

如果能成功唤起你的Instant App,说明配置完全没问题!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.26 10:19:02