17

我想拦截几个不同的链接与我的应用程序,我有意图过滤器数据参数的麻烦做到这一点。Android意图过滤http地址

这里有2种类型的,我想拦截

  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> 

这是我目前试图拦截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> 

感谢,

+0

嘿@leo我想实现同样的事情,我只是想打开我的应用程序时,用户从浏览器启动移动网站我做了同样的事情在这里,但它没有任何帮助? – Tony 2016-05-23 01:20:55

回答

3

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

+0

这绝对是一种可能性,但涉及改变服务器行为,希望不会那样做。任何其他可能性? – Leo 2011-05-30 22:35:34

+0

我没有看到pathFragment的任何选项。你能不能抓住所有发送到“/”的内容并在稍后获取ID? – user775598 2011-05-30 22:37:29

+0

不幸的是,如果我拦截所有在其中都有斜线的链接,我会阻止我的短网址解析,并且无法弄清楚实际目标是什么。 – Leo 2011-05-30 22:47:38