我正在尝试通过我的应用拦截几个不同的链接,但我在使用 Intent 过滤器数据参数时遇到了问题。
这是我要拦截的两种链接
我已经决定有一个单独的 Activity 来拦截两个链接并使用 java 正则表达式来启动正确的 Activity 。但是,如果不捕获 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,但由于某种原因它不起作用。
此 Intent 过滤器正确拦截类型 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...”被省略了,因为它是 fragment 的一部分。如果您改用 http://www.domain.com/id/abcdef123456,pathPattern 可以匹配“/id/.*”,因为它是路径的一部分。
关于用于 http 地址的 Android Intent-Filter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6179776/