2014-12-13 44 views
10

有没有可能在android:host属性上使用通配符?通配符上的Android主机意图过滤器

喜欢的东西:

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

甚至

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

我试图找到这个问题的答案,以及,我会让你知道我什么时候有消息。 – 2015-03-05 16:06:46

回答

11

是。在阅读IntentFilter.AuthorityEntry.match()的Android代码后,我可以看到有一种方法可以将通配符放在主机上,但只能匹配主机的开始。规则如下:

  • 把*作为主机的第一个字符。
  • 写下主机的其余部分直到最后。

这将工作

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

它可以捉住的链接:

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

在另一方面下方一个都不行

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

这不会也赶上othersite.com? – axelbrz 2017-02-13 00:07:04

+0

是的,但如果你想赶上“site.com”,这是你需要做的。 – 2017-07-28 08:12:53