http://host.com/app > http://host.com/app/ > http://host.com/-6ren">
gpt4 book ai didi

android - 匹配 "/app"而不是 "/appinst"与 android :pathPattern (working on an intent-filter)

转载 作者:行者123 更新时间:2023-11-29 02:04:24 28 4
gpt4 key购买 nike

我正在尝试制定一个过滤某些特定网址的 Intent 。我要捕获的网址是:

这可以通过

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

我的问题来了,因为我已经有一个 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/.*]"

但没有一个有效。甚至 [app\\?.*] 打开了/appinstall。

注意:在有人问之前。我有/appinstall Controller ,因为我正在开发的应用程序开始成为 iPhone 应用程序和 appInstall url 有很多情况可以处理重定向到应用程序商店。

最佳答案

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

<!-- 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>元素:

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

关于android - 匹配 "/app"而不是 "/appinst"与 android :pathPattern (working on an intent-filter),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10871065/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com