如何解决用于http地址的Android Intent过滤器
| 我正在尝试拦截与我的应用程序的几个不同链接,而我在使用意图过滤器数据参数时遇到了麻烦。 这是我要拦截的两种链接类型 http://www.domain.com/#id=abcdef123346 http://www.domain.com/social/landing/abcdef123456 我已经决定有一个单独的活动来拦截两个链接,并使用java regex启动正确的活动。但是,我似乎无法不捕获http://www.domain.com/abc123之类的内容而仅捕获这两种格式<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:scheme=\"http\"
android:host=\"www.domain.com\"
android:pathPattern=\"/#id.*\" />
</intent-filter>
这是我目前试图拦截类型1的原因,由于某种原因,它无法正常工作。
此意图过滤器正确拦截了类型2
<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:scheme=\"http\" />
<data android:host=\"domain.com\" />
<data android:host=\"www.domain.com\" />
<data android:pathPrefix=\"/share/web\" />
<data android:pathPrefix=\"/social/landing\" />
</intent-filter>
谢谢,
解决方法
我认为pathPattern匹配的字符串是\“ / \”,而省略了\“#id ... \”,因为它是片段的一部分。如果您改用http://www.domain.com/id/abcdef123456,则pathPattern可以匹配\“ / id /.* \”,因为它是路径的一部分。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。