2017-06-13 7 views
2

私は、例えばドメインexample.comを持っています。 httpshttpの両方で動作します。私はこのサービスのAndroidクライアントを持っています。クライアントが複数のリンクタイプを開くことができるようにしたい。ここには次のものがあります。さまざまなアクティビティでアプリリンクを処理するにはどうすればよいですか?

http://example.com 
https://example.com 
http://example.com/app 
https://example.com/app 

これらの4つは、ListActivityで開く必要があります。しかし、次のような別のリンクもあります:

https://testask.com/i/__some_guid__ 
https://testask.com/item/__some_guid__ 
and relevant link without https 

これらは、別のアクティビティ、たとえばDetailsActivityで開く必要があります。現在、私はDetailsActivityの次のインテントフィルタを持っています。

<intent-filter 
    android:autoVerify="true" 
    tools:targetApi="m"> 
    <action android:name="android.intent.action.VIEW" /> 

    <category android:name="android.intent.category.DEFAULT" /> 
    <category android:name="android.intent.category.BROWSABLE" /> 

    <data android:scheme="http" /> 
    <data android:scheme="https" /> 
    <data 
     android:host="@string/root_host_endpoint" 
     android:pathPattern="/i/.*" /> 
    <data 
     android:host="@string/root_host_endpoint" 
     android:pathPattern="/item/.*" /> 
</intent-filter> 

正しく動作しているようです。しかし、私は理解していない、どのようにルートのホストURLをポイントし、DetailsActivityインテントフィルターをオーバーラップしないようにMainActivityインテントフィルターを追加する。

答えて

0

Welp、いくつかの実験の後、私は期待通り、以下のインテントフィルタが機能していることがわかった:

 <intent-filter 
      android:autoVerify="true" 
      tools:targetApi="m"> 
      <action android:name="android.intent.action.VIEW" /> 

      <category android:name="android.intent.category.DEFAULT" /> 
      <category android:name="android.intent.category.BROWSABLE" /> 

      <data android:scheme="http" /> 
      <data android:scheme="https" /> 
      <data android:host="@string/root_host_endpoint" /> 
      <data 
       android:host="@string/root_host_endpoint" 
       android:path="/" /> 
      <data 
       android:host="@string/root_host_endpoint" 
       android:path="/app" /> 
     </intent-filter> 
0

異なるインテントフィルターで複数のアクティビティーを持つことができます。アクション/カテゴリ/データを使用してインテントフィルタを区別できます。あなたのケースでは、異なる意図を扱うためにデータ設定を微調整する必要があります。 DetailsActivity

とは対照的に、そうMainActivity/ListActivityは異なるデータ構造を持つことになります
+0

おかげで、私はそれは、私を理解しますちょうどxmlでそれを書く方法を取得していませんでした。 – Bringoff

0
<activity android:name=".ListActivity"> 
<intent-filter 
android:autoVerify="true" 
tools:targetApi="m"> 
<action android:name="android.intent.action.VIEW" /> 

<category android:name="android.intent.category.DEFAULT" /> 
<category android:name="android.intent.category.BROWSABLE" /> 

<data android:scheme="http" /> 
<data android:scheme="https" /> 
<data 
    android:host="example.com" 
    android:pathPattern="/*/.*" /> 
</intent-filter> 
</activity> 

<activity android:name=".DetailsActivity"> 
<intent-filter 
android:autoVerify="true" 
tools:targetApi="m"> 
<action android:name="android.intent.action.VIEW" /> 

<category android:name="android.intent.category.DEFAULT" /> 
<category android:name="android.intent.category.BROWSABLE" /> 

<data android:scheme="http" /> 
<data android:scheme="https" /> 
<data 
    android:host="@string/root_host_endpoint" 
    android:pathPattern="/i/.*" /> 
<data 
    android:host="@string/root_host_endpoint" 
    android:pathPattern="/item/.*" /> 
</intent-filter> 
</activity> 
+0

残念ながらリンクリンクは処理されません http://example.com https://example.com http://example.com/app https://example.com/app – Bringoff

+0

<データ android:host = "example.com" android:path = "/ app" /> –

関連する問題