如何在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 specificpathPrefix="/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/xyzand query-param-based likeexample.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
/exclusionfilter comes before your general filter in the manifest—order matters for matching priority. - The
queryPatternensures your query-param-based URLs are explicitly matched, avoiding any ambiguity with the general/.*pattern.
内容的提问来源于stack exchange,提问作者JAW
相关产品推荐
相关产品推荐

