我一直在阅读有关支持Android和应用程序支持的网站的文档的信息,而我的应用程序支持的网站可与子域一起使用,但子域过多,而且它们是动态构建的。我想知道是否有一种方法可以支持许多子域,而不必在intent-filter标签中全部指定它们。

这是来自Google的示例的链接:http://developer.android.com/training/app-links/index.html#request-verify
该示例位于“支持”应用程序中,用于链接多个子域。

我以为正则表达式可以正常工作,但是在定义主机时显然不支持该正则表达式。我不想列出所有这些,因为那意味着必须在创建了每个新的子域的情况下推送新版本

<activity ...>
    <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="https" />
        <data android:host=".*.example.org" />
        <data android:pathPattern="/.*" />
    </intent-filter>
</activity>

我不希望使用第三方库或服务。.但是,对您有用的任何建议,如果能理解如何使它起作用,将不胜感激。

最佳答案

引用自:Verify Android App Links

或者,如果用通配符声明主机名(例如* .example.com),则必须在根主机名(example.com)上发布assetlinks.json文件。例如,只要assetlinks.json文件发布在https://example.com/,具有以下 Intent 过滤器的应用将通过example.com的任何子名称(例如foo.example.com)的验证。 .well-known/assetlinks.json:

<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>

似乎以前的答案已经过时,Android现在确实支持主机名中的通配符。根据文档,现在支持。

10-05 17:41
查看更多