2

特定のURLをフィルタリングするインテントを作成しようとしています。私がキャッチしようとしているURLは次のとおりです。

それはによって行うことができます

<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をすでに持っているために発生します。

そして、私はその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/.*]"

そのうちの1つは機能しませんでした。[app\\?.*]/appinstallを開いても。

注:誰かが尋ねる前に。私が取り組んでいるアプリが始まり、iPhoneアプリとappInstall urlには、アプリストアへのリダイレクトを処理するケースがたくさんあるため、/appinstallコントローラーを使用しています。

4

2 に答える 2

2

これは正確にのパスと一致し、無視されるため、android:path代わりにandroid:pathPrefixorを使用する必要があります。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" />

Web サイトのルートにも一致させたい場合は、次の<data>要素を追加する必要があります。

<data android:scheme="http" android:host="host.com" android:path="/" />
于 2012-08-21T08:30:09.643 に答える
0

android:pathPattern は非常に初歩的であり、実際には正規表現ではありません。演算子 "." のみを許可します。と "*"。

目標を達成するには、非常に賢くなければなりません。一つの方法かもしれません...

<!-- Matches "http://host.com/app" exactly, URLs that will match:
       http://host.com/app
       http://host.com/app/
 -->
<data android:scheme="http" android:host="host.com" android:path="/" />

<!-- Matches URLs prefixed with "http://host.com/app/"
       http://host.com/app/
       http://host.com/app/?query=value
       http://host.com/app/somepage.htm
 -->
<data android:scheme="http" android:host="host.com" android:pathPrefix="/app/" />

<!-- Matches URLs prefixed with "http://host.com/app?"
       http://host.com/app?query=value
 -->
<data android:scheme="http" android:host="host.com" android:pathPrefix="/app?" />

編集:

上記は無視してください。照合できる「パス」には、URL のクエリ文字列やフラグメント識別子の部分、または末尾のスラッシュが含まれていないため、これが正しくないことがわかりました。すぐに別の答えを提供します。

于 2012-08-16T15:54:52.573 に答える