實作應用程式連結功能時,請測試連結功能,確保系統能將應用程式與網站建立關聯,並按照預期處理網址要求。
如要測試現有的聲明檔案,可以使用聲明清單產生器和測試工具。
以下各節說明如何手動測試應用程式連結驗證。您也可以使用 Play 深層連結工具或 Android Studio 應用程式連結小幫手測試驗證。
確認要驗證的主機清單
測試時,請確認系統應為應用程式驗證的相關聯主機清單。請列出所有網址,這些網址對應的意圖篩選器包含下列屬性和元素:
- 值為
http
或https
的android:scheme
屬性 - 含有網域網址模式的
android:host
屬性 android.intent.action.VIEW
動作元素android.intent.category.BROWSABLE
類別元素
請使用這份清單,確認每個具名主機和子網域都提供 Digital Asset Links JSON 檔案。
確認 Digital Asset Links 檔案
針對每個網站,使用 Digital Asset Links API 確認 Digital Asset Links JSON 檔案是否已正確代管及定義:
https://digitalassetlinks.googleapis.com/v1/statements:list?
source.web.site=https://<var>domain.name</var>:<var>optional_port</var>&
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
。這個狀態後方的十六進位數字與 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)
如要進一步瞭解對帳單清單,請參閱「建立對帳單清單」