アプリリンクをテストする

アプリリンク機能を実装する場合は、リンク機能をテストして、想定どおりにシステムでアプリをウェブサイトに関連付けることができ、URL リクエストを処理できることを確認する必要があります。

既存のステートメント ファイルをテストするには、ステートメント リスト生成テストツールを使用できます。

以降のセクションでは、アプリリンクの検証を手動でテストする方法について説明します。必要に応じて、Google Play のディープリンク ツールまたは Android Studio のアプリリンク アシスタントから検証をテストすることもできます。

検証するホストのリストを確定する

テストを行う際は、アプリに関して検証が必要な関連ホストのリストを確定する必要があります。対象インテント フィルタが以下の属性と要素を含むすべての URL のリストを作成します。

  • http または https の値が指定されている android:scheme 属性
  • ドメイン URL パターンが指定されている android:host 属性
  • android.intent.action.VIEW アクション要素
  • android.intent.category.BROWSABLE カテゴリ要素

このリストを使用して、指定された名前の各ホストおよび各サブドメイン上に Digital Asset Links JSON ファイルが用意されているかチェックします。

Digital Asset Links ファイルを確認する

ウェブサイトごとに、Digital Asset Links API を使用して、デジタル アセットリンク JSON ファイルが正しくホストされ定義されていることを確認します。

https://digitalassetlinks.googleapis.com/v1/statements:list?
   source.web.site=https://<var>domain.name</var>:<var>optional_port</var>&amp;
   relation=delegate_permission/common.handle_all_urls

ダイナミック アプリリンクの場合、関連付け拡張機能も確認できます。

https://digitalassetlinks.googleapis.com/v1/statements:list?source.web.site=https://www.example.com&relation=delegate_permission/common.handle_all_urls&return_relation_extensions=true

テストプロセスの一部として、リンク処理の現在のシステム設定をチェックできます。次のコマンドを使用して、コネクテッド デバイス上のすべてのアプリを対象に、既存のリンク処理ポリシーのリストを取得します。

adb shell dumpsys package domain-preferred-apps

次のコマンドでも同じ処理を行うことができます。

adb shell dumpsys package d

このコマンドにより、デバイス上で定義されている各ユーザーまたはプロファイルのリストが返されます。リストの先頭には、次の形式のヘッダーが付きます。

App linkages for user 0:

このヘッダーに続いて、次の形式のリストを使用して、対象ユーザーのリンク処理設定が出力されます。

Package: com.android.vending
Domains: play.google.com market.android.com
Status: always : 200000002

このリストは、対象ユーザーに関して、どのアプリがどのドメインに関連付けられているのかを示しています。

  • Package - マニフェスト内で宣言されているパッケージ名に基づいて、アプリを識別します。
  • Domains - このアプリがウェブリンクを処理するホストの全リストを示します。区切り文字としてスペースを使用します。
  • Status - このアプリの現在のリンク処理設定を示します。検証に合格したアプリがマニフェスト内に android:autoVerify="true" を含んでいる場合、ステータス always が示されます。このステータスの後ろにある 16 進数は、ユーザーのアプリリンク設定に関して Android システムが記録する際に使用するものです。この値は検証が成功したかどうかを示すものではありません。

テストの例

アプリリンクの検証が成功するには、アプリリンクの基準を満たす特定のインテント フィルタで指定されている各ウェブサイトを対象にして、アプリを検証できる必要があります。複数のアプリリンクが定義されているマニフェスト構成の例を以下に示します。

<activity android:name=”MainActivity”>
        <intent-filter android:autoVerify="true">
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="https" />
            <data android:scheme="https" />
            <data android:host="www.example.com" />
            <data android:host="mobile.example.com" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="https" />
            <data android:host="www.example2.com" />
        </intent-filter>
    </activity>

    <activity android:name=”SecondActivity”>
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="https" />
            <data android:host="account.example.com" />
        </intent-filter>
    </activity>

      <activity android:name=”ThirdActivity”>
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:scheme="https" />
            <data android:host="map.example.com" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="market" />
            <data android:host="example.com" />
        </intent-filter>
      </activity>

</application>

上記のマニフェストで、プラットフォームが検証を試みるホストのリストは次のとおりです。

www.example.com
mobile.example.com
www.example2.com
account.example.com

上記のマニフェストで、プラットフォームが検証を試みないホストのリストは次のとおりです。

map.example.com (it does not have android.intent.category.BROWSABLE)
market://example.com (it does not have either an "http" or "https" scheme)

ステートメント リストの詳細については、ステートメント リストを作成するをご覧ください。