我正在尝试设置一个意图过滤器,以便在用户单击以下 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)
意图过滤器的使用Uri匹配器 http://developer.android.com/reference/android/content/UriMatcher.html解析 URI 并确定是否存在匹配。#
是数字的 URI 通配符,如示例中所示Uri匹配器 http://developer.android.com/reference/android/content/UriMatcher.html。根据UriMatcher源代码 https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/java/android/content/UriMatcher.java,没有转义序列来转义 a#
在 URI 中。因此,您应该使用另一个非保留符号(请注意*
也保留作为任何文本的通配符)。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)