本指南說明如何使用 Kotlin 或 Java 將應用程式內評論整合至您的應用程式。如果您使用原生程式碼或 Unity,則有單獨的整合指南。
設定開發環境
In-App Review 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 { task -> if (task.isSuccessful) { // We got the ReviewInfo object val reviewInfo = task.result } else { // There was some problem, log or handle the error code. @ReviewErrorCode val reviewErrorCode = (task.getException() as TaskException).errorCode } }
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, log or handle the error code. @ReviewErrorCode int reviewErrorCode = ((TaskException) task.getException()).getErrorCode(); } });
啟動應用程式內評論流程
使用 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. });
後續步驟
測試應用程式的應用程式內評論流程以確認這項整合機制可正常運作。