Correzione

In questa pagina viene descritto come gestire i problemi relativi agli esiti relativi all'integrità.

Quando viene richiesto un token di integrità, puoi mostrare all'utente una finestra di dialogo di Google Play. Puoi visualizzare la finestra di dialogo in caso di uno o più problemi relativi all'esito relativo all'integrità. La finestra di dialogo viene visualizzata nella parte superiore dell'app e chiede agli utenti di risolvere la causa del problema. Dopo aver chiuso la finestra di dialogo, puoi verificare che il problema sia stato risolto con un'altra richiesta all'API Integrity.

Finestre di dialogo sull'integrità

GET_LICENSED (codice tipo 1)

Problema del verdetto

Quando appLicensingVerdict == "UNLICENSED". Ciò significa che l'account utente non è autorizzato. In altre parole, non ha installato o acquistato l'app da Google Play.

Correzione

Puoi mostrare la finestra di dialogo GET_LICENSED per chiedere all'utente di scaricare la tua app da Google Play. Se l'utente accetta, l'account utente diventa autorizzato (appLicensingVerdict == "LICENSED"). L'app viene aggiunta alla raccolta di Google Play dell'utente e Google Play può fornire aggiornamenti dell'app per tuo conto.

UX di esempio

GET_LICENSED Finestra di dialogo Riproduci

Richiedi una finestra di dialogo sull'integrità

Quando il client richiede un token di integrità, puoi utilizzare il metodo offerto in StandardIntegrityToken (API Standard) e IntegrityTokenResponse (API classica): showDialog(Activity activity, int integrityDialogTypeCode).

I passaggi seguenti spiegano come usare l'API Play Integrity per visualizzare la finestra di dialogo GET_LICENSED:

  1. Richiedi un token di integrità dalla tua app e invialo al tuo server. Puoi utilizzare la richiesta Standard o Classic.

    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. Sul server, decripta il token di integrità e controlla il campo appLicensingVerdict. L'aspetto potrebbe essere simile al seguente:

    // Licensing issue
    {
      ...
      accountDetails: {
        appLicensingVerdict: "UNLICENSED"
      }
    }
    
  3. Se il token contiene appLicensingVerdict: "UNLICENSED", rispondi al client dell'app richiedendo di mostrare la finestra di dialogo delle licenze:

    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. Nell'app, chiama showDialog con il codice richiesto recuperato dal tuo server:

    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. La finestra di dialogo viene visualizzata sopra l'attività fornita. Quando l'utente ha chiuso la finestra di dialogo, l'attività viene completata con un codice di risposta.

  6. (Facoltativo) Richiedi un altro token per visualizzare altre finestre di dialogo. Se esegui richieste standard, devi eseguire di nuovo il riscaldamento del provider di token per ottenere un nuovo esito.