2012-03-18 37 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" />