Correction

Cette page explique comment gérer les problèmes liés aux évaluations de l'intégrité.

Lorsqu'un jeton d'intégrité est demandé, vous avez la possibilité d'afficher une boîte de dialogue Google Play. Vous pouvez afficher la boîte de dialogue en cas de problème lié à l'évaluation de l'intégrité. La boîte de dialogue s'affiche en haut de votre application et invite les utilisateurs à résoudre la cause du problème. Une fois la boîte de dialogue fermée, vous pouvez vérifier que le problème est résolu en envoyant une autre requête à l'API Integrity.

Boîtes de dialogue sur l'intégrité

GET_LICENSED (code de type 1)

Problème d'évaluation

Lorsque appLicensingVerdict == "UNLICENSED". Cela signifie que le compte utilisateur ne possède pas de licence. En d'autres termes, l'utilisateur n'a pas installé ni acheté l'application sur Google Play.

Correction

Vous pouvez afficher la boîte de dialogue GET_LICENSED pour inviter l'utilisateur à télécharger votre application depuis Google Play. Si l'utilisateur accepte, le compte utilisateur se voit attribuer une licence (appLicensingVerdict == "LICENSED"). L'application est ajoutée à la bibliothèque Google Play de l'utilisateur, et Google Play peut fournir des mises à jour d'application en votre nom.

Exemple d'expérience utilisateur

Boîte de dialogue Google Play GET_LICENSED

Demander une boîte de dialogue d'intégrité

Lorsque le client demande un jeton d'intégrité, vous pouvez utiliser la méthode proposée dans StandardIntegrityToken (API standard) et IntegrityTokenResponse (API classique) : showDialog(Activity activity, int integrityDialogTypeCode).

Pour afficher la boîte de dialogue GET_LICENSED à l'aide de l'API Play Integrity, procédez comme suit :

  1. Demandez un jeton d'intégrité à votre application et envoyez-le à votre serveur. Vous pouvez utiliser la requête standard ou classique.

    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. Sur votre serveur, déchiffrez le jeton d'intégrité et vérifiez le champ appLicensingVerdict. Voici ce que vous pourriez voir s'afficher :

    // Licensing issue
    {
      ...
      accountDetails: {
        appLicensingVerdict: "UNLICENSED"
      }
    }
    
  3. Si le jeton contient appLicensingVerdict: "UNLICENSED", répondez au client de votre application en lui demandant d'afficher la boîte de dialogue d'attribution de licences :

    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. Dans votre application, appelez showDialog avec le code demandé récupéré à partir de votre serveur :

    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 boîte de dialogue s'affiche au-dessus de l'activité fournie. Lorsque l'utilisateur a fermé la boîte de dialogue, la tâche se termine avec un code de réponse.

  6. (Facultatif) Demandez un autre jeton pour afficher d'autres boîtes de dialogue. Si vous effectuez des requêtes standards, vous devez rafraîchir le fournisseur de jetons pour obtenir une nouvelle évaluation.