Intégrer des avis dans l'application (Kotlin ou Java)
Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Ce guide explique comment intégrer des avis dans votre application à l'aide de Kotlin ou de Java. Il existe des guides d'intégration distincts selon que vous utilisez du code natif, Unity ou Unreal Engine.
Configurer l'environnement de développement
La bibliothèque Play In-App Review fait partie des bibliothèques Google Play Core.
Incluez la dépendance Gradle suivante pour intégrer la bibliothèque Play In-App Review.
Groovy
// In your app's build.gradle file:...dependencies{// This dependency is downloaded from the Google's Maven repository.// So, make sure you also include that repository in your project's build.gradle file.implementation'com.google.android.play:review:2.0.2'// For Kotlin users also add the Kotlin extensions library for Play In-App Review:implementation'com.google.android.play:review-ktx:2.0.2'...}
Kotlin
// In your app's build.gradle.kts file:...dependencies{// This dependency is downloaded from the Google's Maven repository.// So, make sure you also include that repository in your project's build.gradle file.implementation("com.google.android.play:review:2.0.2")// For Kotlin users also import the Kotlin extensions library for Play In-App Review:implementation("com.google.android.play:review-ktx:2.0.2")...}
Créer le ReviewManager
ReviewManager est l'interface qui permet à votre application de lancer un flux d'avis dans l'application. Pour l'obtenir, créez une instance à l'aide de ReviewManagerFactory.
Suivez les conseils pour savoir quand demander un avis dans l'application afin de déterminer les points clés du parcours utilisateur dans votre application et inviter l'utilisateur à donner son avis (par exemple, lorsqu'il termine un niveau dans un jeu). Lorsque votre application atteint l'un de ces points, utilisez l'instance ReviewManager pour créer une tâche de demande. Si l'opération réussit, l'API renvoie l'objet ReviewInfo nécessaire pour lancer le flux d'avis dans l'application.
Kotlin
valrequest=manager.requestReviewFlow()request.addOnCompleteListener{task->if(task.isSuccessful){// We got the ReviewInfo objectvalreviewInfo=task.result}else{// There was some problem, log or handle the error code.@ReviewErrorCodevalreviewErrorCode=(task.getException()asReviewException).errorCode}}
Java
ReviewManagermanager=ReviewManagerFactory.create(this);Task<ReviewInfo>request=manager.requestReviewFlow();request.addOnCompleteListener(task->{if(task.isSuccessful()){// We can get the ReviewInfo objectReviewInforeviewInfo=task.getResult();}else{// There was some problem, log or handle the error code.@ReviewErrorCodeintreviewErrorCode=((ReviewException)task.getException()).getErrorCode();}});
Lancer la procédure d'examen dans l'application
Utilisez l'instance ReviewInfo pour lancer le flux d'avis dans l'application. Attendez que l'utilisateur ait terminé le flux d'avis avant que votre application poursuive le parcours utilisateur normal (par exemple, passer au niveau suivant).
Kotlin
valflow=manager.launchReviewFlow(activity,reviewInfo)flow.addOnCompleteListener{_->// The flow has finished. The API does not indicate whether the user// reviewed or not, or even whether the review dialog was shown. Thus, no// matter the result, we continue our app flow.}
Java
Task<Void>flow=manager.launchReviewFlow(activity,reviewInfo);flow.addOnCompleteListener(task->{// The flow has finished. The API does not indicate whether the user// reviewed or not, or even whether the review dialog was shown. Thus, no// matter the result, we continue our app flow.});
Le contenu et les exemples de code de cette page sont soumis aux licences décrites dans la Licence de contenu. Java et OpenJDK sont des marques ou des marques déposées d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/08/21 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Il n'y a pas l'information dont j'ai besoin","missingTheInformationINeed","thumb-down"],["Trop compliqué/Trop d'étapes","tooComplicatedTooManySteps","thumb-down"],["Obsolète","outOfDate","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Mauvais exemple/Erreur de code","samplesCodeIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 2025/08/21 (UTC)."],[],[],null,["# Integrate in-app reviews (Kotlin or Java)\n\nThis guide describes how to integrate in-app reviews in your app using either\nKotlin or Java. There are separate integration guides if you are using [native\ncode](/guide/playcore/in-app-review/native), [Unity](/guide/playcore/in-app-review/unity) or [Unreal Engine](/guide/playcore/in-app-review/unreal-engine).\n\nSet up your development environment\n-----------------------------------\n\nThe Play In-App Review Library is a part of the [Google Play Core libraries](/guide/playcore).\nInclude the following Gradle dependency to integrate the Play In-App Review\nLibrary. \n\n### Groovy\n\n```groovy\n// In your app's build.gradle file:\n...\ndependencies {\n // This dependency is downloaded from the /studio/build/dependencies#google-maven.\n // So, make sure you also include that repository in your project's build.gradle file.\n implementation 'com.google.android.play:review:2.0.2'\n\n // For Kotlin users also add the Kotlin extensions library for Play In-App Review:\n implementation 'com.google.android.play:review-ktx:2.0.2'\n ...\n}\n```\n\n### Kotlin\n\n```kotlin\n// In your app's build.gradle.kts file:\n...\ndependencies {\n // This dependency is downloaded from the /studio/build/dependencies#google-maven.\n // So, make sure you also include that repository in your project's build.gradle file.\n implementation(\"com.google.android.play:review:2.0.2\")\n\n // For Kotlin users also import the Kotlin extensions library for Play In-App Review:\n implementation(\"com.google.android.play:review-ktx:2.0.2\")\n ...\n}\n```\n\nCreate the ReviewManager\n------------------------\n\nThe [`ReviewManager`](/reference/com/google/android/play/core/review/ReviewManager) is the interface that lets your app start an in-app\nreview flow. Obtain it by creating an instance using the\n[`ReviewManagerFactory`](/reference/com/google/android/play/core/review/ReviewManagerFactory). \n\n### Kotlin\n\n```kotlin\nval manager = ReviewManagerFactory.create(context)\n```\n\n### Java\n\n```java\nReviewManager manager = ReviewManagerFactory.create(context)\n```\n\nRequest a ReviewInfo object\n---------------------------\n\nFollow the guidance about [when to request in-app reviews](/guide/playcore/in-app-review#when-to-request) to determine good\npoints in your app's user flow to prompt the user for a review (for example,\nwhen the user completes a level in a game). When your app reaches one of these\npoints, use the [`ReviewManager`](/reference/com/google/android/play/core/review/ReviewManager) instance to create a request task. If\nsuccessful, the API returns the [`ReviewInfo`](/reference/com/google/android/play/core/review/ReviewInfo) object needed to start the\nin-app review flow. \n\n### Kotlin\n\n```kotlin\nval request = manager.requestReviewFlow()\nrequest.addOnCompleteListener { task -\u003e\n if (task.isSuccessful) {\n // We got the ReviewInfo object\n val reviewInfo = task.result\n } else {\n // There was some problem, log or handle the error code.\n @ReviewErrorCode val reviewErrorCode = (task.getException() as ReviewException).errorCode\n }\n}\n```\n\n### Java\n\n```java\nReviewManager manager = ReviewManagerFactory.create(this);\nTask\u003cReviewInfo\u003e request = manager.requestReviewFlow();\nrequest.addOnCompleteListener(task -\u003e {\n if (task.isSuccessful()) {\n // We can get the ReviewInfo object\n ReviewInfo reviewInfo = task.getResult();\n } else {\n // There was some problem, log or handle the error code.\n @ReviewErrorCode int reviewErrorCode = ((ReviewException) task.getException()).getErrorCode();\n }\n});\n```\n| **Note:** The [`ReviewInfo`](/reference/com/google/android/play/core/review/ReviewInfo) object is only valid for a limited amount of time. Your app should request a `ReviewInfo` object ahead of time (pre-cache) but only once you are certain that your app will launch the in-app review flow.\n\nLaunch the in-app review flow\n-----------------------------\n\nUse the [`ReviewInfo`](/reference/com/google/android/play/core/review/ReviewInfo) instance to launch the in-app review flow. Wait until\nthe user has completed the in-app review flow before your app continues its\nnormal user flow (such as advancing to the next level). \n\n### Kotlin\n\n```kotlin\nval flow = manager.launchReviewFlow(activity, reviewInfo)\nflow.addOnCompleteListener { _ -\u003e\n // The flow has finished. The API does not indicate whether the user\n // reviewed or not, or even whether the review dialog was shown. Thus, no\n // matter the result, we continue our app flow.\n}\n```\n\n### Java\n\n```java\nTask\u003cVoid\u003e flow = manager.launchReviewFlow(activity, reviewInfo);\nflow.addOnCompleteListener(task -\u003e {\n // The flow has finished. The API does not indicate whether the user\n // reviewed or not, or even whether the review dialog was shown. Thus, no\n // matter the result, we continue our app flow.\n});\n```\n| **Important:** If an error occurs during the in-app review flow, do not inform the user or change your app's normal user flow. Continue your app's normal user flow after `onComplete` is called.\n\nNext steps\n----------\n\n[Test your app's in-app review flow](/guide/playcore/in-app-review/test) to verify that your integration is\nworking correctly."]]