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

标签 android android-intent

我正在尝试创建一个过滤某些特定网址的 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>

我的问题出现是因为我已经有一个网址:

而且我不想尝试在该网址中打开应用程序。

我已经尝试过了

  • android:pathPattern="[app]
  • android:pathPattern="[app.*]
  • android:pathPattern="[应用程序?.*]
  • 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/

相关文章:

android - 以编程方式设置菜单中的可见性android

android - 解决 Intent Activity 的问题 - resolveActivityInfo()

java - 分享 Instagram Story 的贴纸坏了?

android - 使用标志 FLAG_UPDATE_CURRENT 时,小部件 onclick 未决 Intent 不会触发

android - 使用单击事件以编程方式在android中创建按钮

从另一个 Activity 的 Intent 中检索 int 时,Android 应用程序崩溃

javascript - 使用 cordova 社交共享插件发送带有变量的短信

android - 在 Android 应用发布版本中获取错误的版本代码和版本名称

android - iPhone 上的 Bootstrap 网格系统

android - 调用 Web 服务或任何网络调用时应用程序挂起