改善

このページでは、完全性判定の結果に関する問題への対処方法について説明します。

完全性トークンがリクエストされたときに、ユーザーに Google Play ダイアログを表示できます。完全性判定の結果に 1 つ以上の問題がある場合は、アプリの上部にダイアログを表示して、問題の原因を解消するようユーザーに促すことができます。ダイアログを閉じると、Integrity API への別のリクエストで問題が修正されたことを確認できます。

完全性ダイアログ

GET_LICENSED(タイプコード 1)

判定に関する問題

appLicensingVerdict == "UNLICENSED" の場合は、ユーザー アカウントにライセンスが付与されていないことを意味します。つまり、Google Play からアプリをインストールまたは購入していないということです。

改善

GET_LICENSED ダイアログを表示して、Google Play からアプリを入手するようユーザーに促すことができます。ユーザーが承諾すると、ユーザー アカウントにライセンスが付与されます(appLicensingVerdict == "LICENSED")。アプリがユーザーの Google Play ライブラリに追加され、Google Play を通じてアプリ アップデートを配信できるようになります。

UX の例

Google Play の GET_LICENSED ダイアログ

完全性ダイアログをリクエストする

クライアントが完全性トークンをリクエストすると、StandardIntegrityToken(標準 API)と IntegrityTokenResponse(クラシック API)で提供されているメソッド showDialog(Activity activity, int integrityDialogTypeCode) を使用できます。

Play Integrity API を使用して GET_LICENSED ダイアログを表示する手順は次のとおりです。

  1. アプリから完全性トークンをリクエストし、そのトークンをサーバーに送信します。標準リクエストまたはクラシック リクエストを使用できます。

    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());
    
    
  2. サーバーで、完全性トークンを復号し、appLicensingVerdict フィールドを確認します。次のようになります。

    // Licensing issue
    {
      ...
      accountDetails: {
        appLicensingVerdict: "UNLICENSED"
      }
    }
    
  3. トークンに 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;
    }
    
    
  4. アプリで、サーバーから取得したコードを使用して、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.
    }
    
    
  5. ダイアログは提供されたアクティビティの上に表示されます。ユーザーがダイアログを閉じると、タスクはレスポンス コードを返して完了します。

  6. (省略可)さらにダイアログを表示するには、別のトークンをリクエストします。標準リクエストを実行する場合は、トークン プロバイダを再度ウォームアップして、新しい判定結果を取得する必要があります。