'Android intent filter (android:host) with regexp

Is it possible to have regular expression (regexp) on intent filter to filter various host addresses? I tried to write, but failed, so looking for some help.

I have lot of domains and want to write intent filter to match all these examples:

  1. http://example.com/
  2. http://example.ru/
  3. http://example.org/
  4. http://example.biz/

and more from the previous version that is still supported.

  1. http://previousversion.com/
  2. http://previousversion.ru/

...

also there could be http and https; with and without www.

Below code example is working, but if i want to write all conditions it would take a lot of space in manifest, so I'm looking for a better way. Main point that path prefix is the same, but host and scheme is changing.

<data
     android:host="www.example.com"
     android:pathPrefix="/operation/accept/"
     android:scheme="https"/>

<data
     android:host="example.com"
     android:pathPrefix="/operation/accept/"
     android:scheme="https"/>

<data
     android:host="www.example.com"
     android:pathPrefix="/operation/accept/"
     android:scheme="http"/>

<data
     android:host="example.com"
     android:pathPrefix="/operation/accept/"
     android:scheme="http"/>
...


Solution 1:[1]

It seems like there is no regex supported in android:host, it only supports asterisk wildcard, you could check this https://developer.android.com/guide/topics/manifest/data-element.

But, I found another way to write path only once, like below. (reference: https://riptutorial.com/android/example/12833/multiple-domains-and-multiple-paths)

<data android:scheme="https"
        android:host="*.example.com" />

<data android:scheme="https"
        android:host="*.example2.com" />

<data android:path="/operation/accept/" />

It'll produce following links.

  • https://*.example.com/operation/accept/
  • https://*.example2.com/operation/accept/

Solution 2:[2]

There is no regex support. You can use pathPattern which only allows you to use .* and * wildcards in path segments. For the host you can use * as first character only.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jack Yu
Solution 2