12

我正在尝试设置一个意图过滤器以在用户单击以下 URI 时启动我的活动:example.com/pathA/pathB/#pathC/someGUID

所以我在清单文件中添加了以下 XML:

<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="example.com"
        android:pathPrefix="/pathA/pathB/#pathC"
        android:scheme="http" />
</intent-filter>

我在想 '#' 字符搞砸了一切,但我尝试在没有运气的情况下转义这个字符。有任何想法吗?

更新:当我说“尝试转义”时,我的意思是使用百分比编码(# 等于 %23)

4

1 回答 1

16

Intent 过滤器使用UriMatcher解析 URI 并确定是否存在匹配项。#是数字的 URI 通配符,如UriMatcher中的示例所示。根据UriMatcher 源代码,没有转义序列来转义#URI 中的 a。因此,您应该使用另一个非保留符号(请注意,*它也保留为任何文本的通配符)。

于 2013-05-08T22:26:46.193 回答