android - 匹配 <intent-filter> 中的 url 模式

标签 android android-intent intentfilter

我希望我的一项 Activity 能够获取特定的网址。模式是:

http://www.example.com/abc123/foo/xyz789

路径组件“abc123”和“xyz789”可以是任意字母数字序列,长度> 1。

在我的 list 中这样做:

<activity>
  <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="example.com" 
      android:pathPattern="/.*/foo/.*" />

但似乎我域中的任何模式都在匹配,即:

myexample.com
myexample.com/whatever

两者都匹配。我想也许 .* 运算符没有像我期望的那样工作?任何帮助都会很棒,

谢谢

http://developer.android.com/guide/topics/manifest/data-element.html

最佳答案

我今天也遇到了同样的问题,我的解决方法是:

   <data android:pathPattern="/remotes/..*/..*"/>

使用 (..*) 代替 (.+)

在原始问题的情况下,我想这可以工作:

<data
                android:host="example.com"
                android:pathPattern="..*/foo/..*"
                android:scheme="http"/>

关于android - 匹配 <intent-filter> 中的 url 模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4762251/

相关文章:

java - SecondActivity 未接收值 - Intent 相关

android Charge intent 没有额外数据

android - 如何在完成从推送通知启动的 Activity 后将应用程序发送到后台

android - 在拨号器和通话记录之间切换时联系人应用程序崩溃

android - 使用replace()后如何保存 fragment 的实例状态?

android - finishActivity() 的可能用例是什么

Android - 广播 Intent 中的自定义操作

android - 在 list 文件中指定 Intent 操作的正确方法是什么?

android - 如何在后台线程中使用RX从android中的 Assets 文件夹中读取文件

java - KeyStore 未从文件初始化