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

如何在pathPattern中排除指定目录?Instant App Intent-Filter适配

Solution to Exclude Specific Directory from Instant App Intent Filter

Got it, since you already know your way around pathPatterns for Instant Apps, here's a straightforward solution leveraging Android's intent-filter matching priority:

Android resolves intent filters by prioritizing more specific patterns first. So we'll create a dedicated filter for your /exclusion directory to mark it as BROWSABLE, and keep your existing filter for handling the parameter-based module downloads.

Step-by-Step Implementation

Add this intent filter before your existing one in your manifest:

<!-- Intent filter for /exclusion directory (BROWSABLE only) -->
<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" />

    <!-- Matches /exclusion and all its subpaths (e.g., /exclusion/subpage) -->
    <data
        android:scheme="https"
        android:host="example.com"
        android:pathPrefix="/exclusion" />
</intent-filter>

Keep your original intent filter for handling the parameter-based URLs, with a small adjustment to explicitly cover both path-based and query-param-based formats:

<!-- Original filter for module download URLs -->
<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" />

    <!-- Matches path-based URLs like example.com/abc/xyz -->
    <data
        android:scheme="https"
        android:host="example.com"
        android:pathPattern="/.*" />

    <!-- Matches query-param-based URLs like example.com/?Q1=abc&Q2=xyz -->
    <data
        android:scheme="https"
        android:host="example.com"
        android:path="/"
        android:queryPattern="Q1=.*&Q2=.*" />
</intent-filter>

Why This Works

  • When a user visits example.com/exclusion (or any subpath under it), the first, more specific pathPrefix="/exclusion" filter will be triggered. Since this filter is marked as BROWSABLE, the system will route the URL to a browser instead of your Instant App.
  • All other URLs (both path-based like example.com/abc/xyz and query-param-based like example.com/?Q1=abc&Q2=xyz) will fall through to your original filter, which continues handling the module download logic as expected.

Key Notes

  • Make sure the /exclusion filter comes before your general filter in the manifest—order matters for matching priority.
  • The queryPattern ensures your query-param-based URLs are explicitly matched, avoiding any ambiguity with the general /.* pattern.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.25 07:35:34