如何使用意图过滤器仅过滤特定的URL

11

我想过滤特定的URL:http://gaapa.cz/mobile/*

但这个过滤器会在每个URL上触发 - 这是什么问题?

<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>
3个回答

13
您需要根据这里的文档使用路径、pathPrefixpathPattern
在您的情况下,使用pathPatternpathPrefix都可以。
pathPattern="mobile/*"

或者

pathPrefix="mobile"

然而,这并不能解释为什么您的过滤器匹配所有URI。它应该不匹配任何一个,因为path不理解“*”。我怀疑您的代码中其他地方有些添加/缺失。

1
我的一个意图过滤器缺少主机,因此路径被忽略了。 - Hurda
如果我想为以下URL创建一个过滤器会发生什么: http://gaapa.cz/#/aaa我尝试将pathPrefix或pathPattern更改为“/#/*”或“#/”,但没有成功。 - gaara87
哈希符号是一个保留字符。如果你想在URL中使用它,你需要对它进行编码(%23)。 - Jeffrey Blattman

3

试试这个:

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

2

这个应该可以工作:

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

嗯...android:path="mobile"不起作用,因为它需要一个斜杠"/"。例如:android:path="/mobile"。 - Oscar Salguero

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接