Android host intent filters on a wildcard

2019-03-15 14:29发布

问题:

Is it possible to use wildcards on the android:host attribute ?

Something like:

        android:host="*.site.com"
        android:pathPattern=".*"
        android:pathPrefix="/m/"
        android:scheme="http" />

Or even

        android:host="*.site.*"
        android:pathPattern=".*"
        android:pathPrefix="/m/"
        android:scheme="http" />

回答1:

Yes. After reading the Android code of IntentFilter.AuthorityEntry.match(), I can see that there is a way to put wildcard on host, but only to match the beginning of host. The rules are these:

  • Put * as the first character of the host.
  • Write the rest of of the host until the end.

This will work:

    android:host="*site.com"
    android:pathPattern=".*"
    android:scheme="http" />

It will catch links of:

  • www.site.com
  • site.com
  • mail.site.com

On the other hand the one below won't work:

    android:host="*.site.*"
    android:pathPattern=".*"
    android:scheme="http" />