匹配"/app"而不是"/appinst"与android:pathPattern(在意图过滤器上工作) [英] Match "/app" and not "/appinst" with android:pathPattern (working on an intent-filter)

查看:133
本文介绍了匹配"/app"而不是"/appinst"与android:pathPattern(在意图过滤器上工作)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试过滤某些特定的URL. 我要捕获的网址是:

I'm trying to make an intent that filters some specific urls. The urls that I'm trying to catch are:

  • http://host.com/app
  • http://host.com/app/
  • http://host.com/app?...
  • http://host.com/app/?...

可以通过

<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.BROWSABLE" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:scheme="http" android:host="host.com"
        android:pathPrefix="/app" android:pathPattern="[app.*]"/>
</intent-filter>

我的问题来了,因为我已经有一个网址:

My problem comes because I already have a url that is:

而且我不想尝试在该URL中打开应用程序.

And I don't want to try to open the app in that url.

我已经尝试过

  • android:pathPattern="[app]
  • android:pathPattern="[app.*]
  • android:pathPattern="[app?.*]
  • android:pathPattern="[app\?.*]
  • android:pathPattern="[app\\?.*]
  • android:pathPattern="[app|app?.*]
  • android:pathPattern="[app|app\?.*]
  • android:pathPattern="[app|app\\?.*]
  • android:pathPattern="[nativeapp\z|nativeapp\?.*|nativeapp/.*]"
  • android:pathPattern="[nativeapp\\z|nativeapp\\?.*|nativeapp/.*]"
  • android:pathPattern="[app]
  • android:pathPattern="[app.*]
  • android:pathPattern="[app?.*]
  • android:pathPattern="[app\?.*]
  • android:pathPattern="[app\\?.*]
  • android:pathPattern="[app|app?.*]
  • android:pathPattern="[app|app\?.*]
  • android:pathPattern="[app|app\\?.*]
  • android:pathPattern="[nativeapp\z|nativeapp\?.*|nativeapp/.*]"
  • android:pathPattern="[nativeapp\\z|nativeapp\\?.*|nativeapp/.*]"

,其中没有一个有效. 甚至[app\\?.*]都打开了/appinstall.

and not one of them worked. Even [app\\?.*] opened /appinstall.

注意:在有人问之前.我之所以拥有/appinstall控制器,是因为我正在使用的应用和iPhone应用以及appInstall url在很多情况下都需要处理重定向到应用商店的情况.

Note: before someone asks. I have the /appinstall controller because the app that I'm working on started being and iPhone app and the appInstall url has a lot of cases to treat the redirection to the app store.

推荐答案

您需要使用android:path而不是android:pathPrefixandroid:pathPattern,因为这将完全匹配/app的路径,而/appinstall将是忽略了.

You need to use android:path instead of android:pathPrefix or android:pathPattern since this will match a path of /app exactly and /appinstall will be ignored.

<!-- Matches "http://host.com/app" exactly, note that querystring, fragment
    identifiers and the trailing slash are not considered part of the path and 
    are therefore ignored so URLs that will match:
       http://host.com/app
       http://host.com/app/
       http://host.com/app?some=value
       http://host.com/app/?some=value
       http://host.com/app#fragmentIdentifier
       http://host.com/app/#fragmentIdentifier
       http://host.com/app?some=value#fragmentIdentifier
       http://host.com/app/?some=value#fragmentIdentifier
    URLs that will NOT match
       http://host.com/app/index.htm
       http://host.com/appinstall
       http://host.com/appinstall/
       http://host.com/app/subdirectory
       http://host.com/app/subdirectory/
       http://host.com/apple.htm
 -->
<data android:scheme="http" android:host="host.com" android:path="/app" />

如果您还想匹配网站的根目录,则需要添加一个额外的<data>元素:

If you want to also match the root of the website then you'll need to add an additional <data> element:

<data android:scheme="http" android:host="host.com" android:path="/" />

这篇关于匹配"/app"而不是"/appinst"与android:pathPattern(在意图过滤器上工作)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆