用于http地址的Android Intent-Filter

时间:2021-06-15 21:11:59

I am trying to intercept a couple different links with my app, and I am having trouble with the intent-filter data parameters to do it.

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

Here are the 2 types of links that I want to intercept

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

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

I have already decided to have a separate activity to intercept both links and use java regex to start the correct activity. However I can't seem to capture just these two formats without capturing something like http://www.domain.com/abc123

我已经决定有一个单独的活动来拦截这两个链接并使用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>

This is what I am currently trying to intercept type 1 and for some reason it isn't working.

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

This intent-filter correctly intercepts type 2

此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>

Thanks,

谢谢,

1 个解决方案

#1


3  

I think that the string that pathPattern is matching is "/", and "#id..." is omitted because it is part of the fragment. If you used http://www.domain.com/id/abcdef123456 instead, pathPattern could match "/id/.*" because it is part of the path.

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

#1


3  

I think that the string that pathPattern is matching is "/", and "#id..." is omitted because it is part of the fragment. If you used http://www.domain.com/id/abcdef123456 instead, pathPattern could match "/id/.*" because it is part of the path.

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