// 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")...}
请遵循有关何时请求应用内评价的指南,以确定在应用的用户流的哪些阶段适合提示用户进行评价(例如,当用户在游戏中完成某个关卡时)。当您的应用达到其中一个阶段时,请使用 ReviewManager 实例创建请求任务。如果请求成功,该 API 将返回启动应用内评价流程所需的 ReviewInfo 对象。
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();}});
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.});
[null,null,["最后更新时间 (UTC):2025-08-21。"],[],[],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."]]