带有regexp的Android意图过滤器(android:host)

时间:2015-05-13 06:33:53

标签: android intentfilter

是否可以在intent filter上使用正则表达式(regexp)来过滤各种主机地址?我试着写,但失败了,所以寻求一些帮助。

我有很多域,并希望编写意图过滤器以匹配所有这些示例:

  1. http://example.com/
  2. http://example.ru/
  3. http://example.org/
  4. http://example.biz/
  5. 以及仍受支持的先前版本的更多内容。

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

      也可能有http和https;有和没有www。

      下面的代码示例正在运行,但是如果我想编写所有条件,那么清单中需要占用大量空间,所以我正在寻找更好的方法。路径前缀相同但主机和方案正在改变的要点。

      <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"/>
      ...
      

1 个答案:

答案 0 :(得分:-1)

没有正则表达式支持。您可以使用pathPattern,它只允许您在路径段中使用。*和*通配符。对于主持人,您只能使用*作为第一个字符。