-
更新:现在您可以使用数字资产链接处理通配符域
aurilio explained it in his newer answer
整个过程记录在这里:https://developer.android.com/training/app-links/verify-site-associations
总结一下,现在你可以在host标签中使用通配符,你必须上传一个json文件叫assetlinks.json 到您的 root 域上的 /.well-known 文件夹/路由。
或者,如果您使用通配符声明您的主机名(例如 *.example.com),您必须在根主机名(example.com)发布您的assetlinks.json 文件
您还需要添加属性 android:autoVerify="true" 到您的intent-filter 标签。
这是 Android 端的完整示例:
<application>
<activity android:name=”MainActivity”>
<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" />
<data android:scheme="https" android:host="*.example.com" />
</intent-filter>
</activity>
</application>
这是 2016 年的上一个答案:
不幸的是,Android 似乎无法处理通配符域。
如果您查看 data 标记 (https://developer.android.com/guide/topics/manifest/data-element.html) 的 API 指南,您会看到他们提到通配符可用于 pathPattern 和 mimeType,但不适用于主机。
事实是,正如 CommonsWare 在关于该主题的另一篇文章 (https://stackoverflow.com/a/34068591/4160079) 中所解释的那样,
在安装时会检查域,除了通过发布带有新清单的新版本应用程序之外,无法添加新域。
因此,您必须手动列出所有可用的子域,并在启动新子域时更新应用程序。
以下是您声明多个子域的方式:
<activity android:name="MainActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" />
<data android:host="subdomain1.example.com" />
<data android:host="subdomain2.example.com" />
<data android:host="subdomain3.example.com" />
</intent-filter>
</activity>
- 是的,您只能处理路径的子集
同样的想法,只需使用 path 属性列出您想要的路径(再次,请参阅上面的 data 标签 API 指南)。
如果您使用查询字符串或路径参数,最好使用 pathPrefix。
如有必要,您可以在此处使用通配符,方法是选择 pathPattern。
URI 的路径部分,必须以 / 开头。 path 属性指定与 Intent 对象中的完整路径匹配的完整路径。 pathPrefix 属性指定仅与 Intent 对象中路径的初始部分匹配的部分路径。 pathPattern 属性指定与 Intent 对象中的完整路径匹配的完整路径,但它可以包含以下通配符:
星号 ('') 匹配从 0 到多次出现的前一个字符的序列。
一个句点后跟一个星号 (".") 匹配任何 0 到多个字符的序列。
这里有几个例子:
<activity android:name="MainActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" />
<data android:host="subdomain1.example.com" />
<data android:host="subdomain2.example.com" />
<data android:host="subdomain3.example.com" />
<data android:path="/path1" /> <!-- matches /path1 only -->
<data android:pathPrefix="/path2" /> <!-- matches /path2, /path2/something or also /path2?key=value etc... -->
<data android:pathPattern="/wild.*" /> <!-- matches /wild, /wild3, /wilderness etc... -->
</intent-filter>
</activity>