本指南介绍如何使用 Kotlin 或 Java 将应用内评价集成到您的应用中。如果您使用的是原生代码或 Unity,请参阅单独的集成指南。
设置您的开发环境
应用内评价 API 是 Play Core SDK 的一部分。如需设置开发环境,请按照 Play Core 库指南的 Java 或 Kotlin 部分中的设置说明进行操作。
创建 ReviewManager
ReviewManager
界面可让您的应用启动应用内评价流程。使用 ReviewManagerFactory
创建实例获取该界面。
Kotlin
val manager = ReviewManagerFactory.create(context)
Java
ReviewManager manager = ReviewManagerFactory.create(context)
请求 ReviewInfo 对象
请遵循有关何时请求应用内评价的指南,以确定在应用的用户流的哪些阶段适合提示用户进行评价(例如,当用户在游戏中完成某个关卡时)。当您的应用达到其中一个阶段时,请使用 ReviewManager
实例创建请求任务。如果请求成功,该 API 将返回启动应用内评价流程所需的 ReviewInfo
对象。
Kotlin
val request = manager.requestReviewFlow() request.addOnCompleteListener { request -> if (request.isSuccessful) { // We got the ReviewInfo object val reviewInfo = request.result } else { // There was some problem, continue regardless of the result. } }
Java
ReviewManager manager = ReviewManagerFactory.create(this); Task<ReviewInfo> request = manager.requestReviewFlow(); request.addOnCompleteListener(task -> { if (task.isSuccessful()) { // We can get the ReviewInfo object ReviewInfo reviewInfo = task.getResult(); } else { // There was some problem, continue regardless of the result. } });
启动应用内评价流程
使用 ReviewInfo
实例启动应用内评价流程。等到用户完成应用内评价流程后,再继续执行应用的正常用户流(例如进入下一关)。
Kotlin
val flow = 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. });
后续步骤
测试应用的应用内评价流程,以验证您的集成是否正常运行。