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