2012-03-18 43 views
9

仅过滤特定的URL我要过滤特定网址:http://gaapa.cz/mobile/ *如何使用意图过滤

但这种过滤器被触发每个URL - ehta的错呢?

<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:host="gaapa.cz" 
       android:path="/mobile/.*" 
       android:scheme="http" /> 
</intent-filter> 

回答

10

你想要么使用路径,pathPrefix,或pathPattern,根据,

http://developer.android.com/guide/topics/manifest/data-element.html#path 

在你的情况下,e ither pathPatternpathPrefix将工作,

pathPattern="mobile/*" 

pathPrefix="mobile" 

然而,这并不能解释为什么你的过滤器匹配所有的URI。它应该是匹配没有,因为路径不理解“*”。我怀疑你的代码中有其他地方添加/缺少的东西。

+1

我的意图过滤器之一是丢失主机,所以路径被忽略 – Hurda 2012-03-28 07:13:37

+0

如果我想要为以下url进行过滤,会发生什么情况: http://gaapa.cz/#/aaa 我试图将pathPrefix或pathPattern更改为“/#/ *”或“#/”,它不起作用 – gaara87 2014-07-16 11:56:24

+0

散列是一个保留字符。如果你想在URL中使用它,你需要对它进行编码(%23)。 – 2014-07-17 00:37:11

1

这应该工作:

<data android:host="gaapa.cz" 
     android:path="mobile" 
     android:pathPattern="*" 
     android:scheme="http" /> 
+0

嗯...... android:path =“mobile”不会工作,因为它需要一个前导“/”。例如:android:path =“/ mobile”。 – 2017-01-12 18:16:02

2

试试这个:

<data android:host="gaapa.cz" 
     android:pathprefix="mobile/" 
     android:scheme="http" />