本頁面說明如何處理完整性判定結果的問題。
當您要求系統提供完整性權杖時,您可以選擇向使用者顯示 Google Play 對話方塊。當完整性判定結果有一或多個問題時,系統可能會顯示對話方塊。對話方塊會顯示在應用程式頂端,並提示使用者解決問題。關閉對話方塊後,您便可透過向 Integrity API 提出的另一項要求,確認問題已解決。
完整性對話方塊
GET_LICENSED (類型代碼 1)
判定問題
時間:appLicensingVerdict == "UNLICENSED"
。這表示使用者帳戶未獲得授權。也就是說,使用者並非透過 Google Play 安裝或購買應用程式。
修復
您可以顯示 GET_LICENSED
對話方塊,提示使用者前往 Google Play 取得您的應用程式。如果使用者接受要求,使用者帳戶就會取得授權 (appLicensingVerdict == "LICENSED"
)。應用程式會新增至使用者的 Google Play 媒體庫,Google Play 就能代您提供應用程式更新。
使用者體驗範例
要求完整性對話方塊
當用戶端要求完整性權杖時,您可以使用 StandardIntegrityToken (Standard API) 和 IntegrityTokenResponse (傳統 API) 中提供的方法:showDialog(Activity activity, int integrityDialogTypeCode)
。
下列步驟概述如何使用 Play Integrity API 顯示「GET_LICENSED」對話方塊:
向應用程式要求完整性權杖,並將權杖傳送至伺服器。您可以使用「標準」或「傳統」要求。
Kotlin
// Request an integrity token val tokenResponse: StandardIntegrityToken = requestIntegrityToken() // Send token to app server and get response on what to do next val yourServerResponse: YourServerResponse = sendToServer(tokenResponse.token())
Java
// Request an integrity token StandardIntegrityToken tokenResponse = requestIntegrityToken(); // Send token to app server and get response on what to do next YourServerResponse yourServerResponse = sendToServer(tokenResponse.token());
在伺服器上解密完整性權杖,然後檢查
appLicensingVerdict
欄位。如下所示:// Licensing issue { ... accountDetails: { appLicensingVerdict: "UNLICENSED" } }
如果權杖包含
appLicensingVerdict: "UNLICENSED"
,請回覆您的應用程式用戶端,並要求顯示授權對話方塊:Kotlin
private fun getDialogTypeCode(integrityToken: String): Int{ // Get licensing verdict from decrypted and verified integritytoken val licensingVerdict: String = getLicensingVerdictFromDecryptedToken(integrityToken) return if (licensingVerdict == "UNLICENSED") { 1 // GET_LICENSED } else 0 }
Java
private int getDialogTypeCode(String integrityToken) { // Get licensing verdict from decrypted and verified integrityToken String licensingVerdict = getLicensingVerdictFromDecryptedToken(integrityToken); if (licensingVerdict.equals("UNLICENSED")) { return 1; // GET_LICENSED } return 0; }
在應用程式中使用從伺服器擷取的要求程式碼,呼叫
showDialog
:Kotlin
// Show dialog as indicated by the server val showDialogType: Int? = yourServerResponse.integrityDialogTypeCode() if (showDialogType != null) { // Call showDialog with type code, the dialog will be shown on top of the // provided activity and complete when the dialog is closed. val integrityDialogResponseCode: Task<Int> = tokenResponse.showDialog(activity, showDialogType) // Handle response code, call the Integrity API again to confirm that // verdicts have been resolved. }
Java
// Show dialog as indicated by the server @Nullable Integer showDialogType = yourServerResponse.integrityDialogTypeCode(); if (showDialogType != null) { // Call showDialog with type code, the dialog will be shown on top of the // provided activity and complete when the dialog is closed. Task<Integer> integrityDialogResponseCode = tokenResponse.showDialog(activity, showDialogType); // Handle response code, call the Integrity API again to confirm that // verdicts have been resolved. }
對話方塊會顯示在提供的活動的頂端。當使用者關閉對話方塊時,工作會使用回應代碼完成。
(選用) 要求另一組權杖,以便顯示其他對話方塊。如果您提出標準要求,就必須再次暖機憑證提供者,以取得最新的判定結果。