Android Studio App Links Assistant使用pathPattern匹配数字路径失败如何解决
问题原因
你的匹配失败核心是两个配置错误:
- pathPattern语法使用错误:Android manifest的
pathPattern不支持正则表达式的[0-9]字符组、+量词这类语法,它仅支持非常有限的通配符规则:.匹配任意单个字符*匹配0个或多个紧邻它之前的字符- 其余所有字符均为字面量匹配
- scheme配置不全:你当前仅配置了
httpsscheme,如果你要兼容用户访问http开头的链接,需要额外补充http的配置。
修复方案
1. 修正路径匹配规则
你需要匹配固定9位数字的路径,由于manifest层面无法严格限制仅匹配数字,建议先匹配路径格式,后续在App收到跳转Intent后再对路径内容做正则校验,合法再处理,不合法可直接跳转回浏览器。
匹配/后固定9位字符的pathPattern写法:
android:pathPattern="/........."
(/后加9个.,每个.匹配1位字符,刚好对应9位路径内容)
2. 修正后的完整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" /> <!-- 同时支持http和https --> <data android:scheme="http" /> <data android:scheme="https" /> <data android:host="meet.finitycare.com" android:pathPattern="/........." /> </intent-filter>
3. 后续必要配置
如果你开启了android:autoVerify="true",还需要将对应签名的assetlinks.json文件上传到你域名的/.well-known/目录下,否则系统不会自动验证你的App链接所有权,用户点击链接时会弹出应用选择框,不会直接跳转你的App。
内容的提问来源于stack exchange,提问作者Neglected Sanity
相关产品推荐
相关产品推荐

