用于http地址的Android Intent-Filter

Leo*_*Leo 17 android intentfilter android-manifest android-intent android-activity

我试图拦截我的应用程序的几个不同的链接,我在使用intent-filter数据参数时遇到问题.

以下是我想要拦截的两种类型的链接

  1. http://www.domain.com/#id=abcdef123346
  2. http://www.domain.com/social/landing/abcdef123456

我已经决定有一个单独的活动来拦截这两个链接并使用java正则表达式来启动正确的活动.但是我似乎无法捕获这两种格式而没有捕获像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>
Run Code Online (Sandbox Code Playgroud)

这就是我目前正在尝试拦截类型1,并且由于某种原因它无法正常工作.

此intent-filter正确截取类型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>
Run Code Online (Sandbox Code Playgroud)

谢谢,

小智 4

我认为pathPattern匹配的字符串是“/”,而“#id...”被省略,因为它是片段的一部分。如果您使用http://www.domain.com/id/abcdef123456,则 pathPattern 可以匹配“/id/.*”,因为它是路径的一部分。