Solución

En esta página, se describe cómo abordar problemas relacionados con los veredictos de integridad.

Cuando se solicita un token de integridad, tienes la opción de mostrarle al usuario un diálogo de Google Play. Puedes mostrar el diálogo cuando haya uno o más problemas con el veredicto de integridad. El diálogo se muestra en la parte superior de la app y les pide a los usuarios que resuelvan la causa del problema. Una vez que se cierra el cuadro de diálogo, puedes verificar que el problema se haya solucionado con otra solicitud a la API de Integrity.

Diálogos de integridad

GET_LICENSED (código de tipo 1)

Problema con el veredicto

Cuando ocurre appLicensingVerdict == "UNLICENSED", significa que la cuenta de usuario no tiene licencia. En otras palabras, no instaló ni compró la app desde Google Play.

Solución

Puedes mostrar el diálogo GET_LICENSED para solicitarle al usuario que descargue tu app desde Google Play. Si el usuario acepta, su cuenta obtiene una licencia (appLicensingVerdict == "LICENSED"). La app se agrega a la biblioteca de Google Play del usuario, y Google Play puede entregar actualizaciones de la app en tu nombre.

UX de ejemplo

Diálogo de Play GET_LICENSED

Cómo solicitar un diálogo de integridad

Cuando el cliente solicite un token de integridad, puedes usar el método que se ofrece en StandardIntegrityToken (API estándar) y en IntegrityTokenResponse (API clásica): showDialog(Activity activity, int integrityDialogTypeCode).

En los siguientes pasos, se describe cómo puedes usar la API de Play Integrity para mostrar el diálogo GET_LICENSED:

  1. Solicita un token de integridad a tu app y envíalo a tu servidor. Puedes usar la solicitud estándar o clásica.

    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. En tu servidor, desencripta el token de integridad y verifica el campo appLicensingVerdict. Tal vez se vería así:

    // Licensing issue
    {
      ...
      accountDetails: {
        appLicensingVerdict: "UNLICENSED"
      }
    }
    
  3. Si el token contiene appLicensingVerdict: "UNLICENSED", responde al cliente de tu app y solicítale que muestre el diálogo de licencia:

    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. En tu app, llama a showDialog con el código solicitado recuperado de tu servidor:

    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. El diálogo se muestra en la parte superior de la actividad proporcionada. Cuando el usuario cierra el diálogo, la tarea se completa con un código de respuesta.

  6. (Opcional) Solicita otro token para mostrar otros diálogos. Si realizas solicitudes estándar, debes volver a preparar el proveedor de tokens para obtener un veredicto nuevo.