คู่มือนี้อธิบายวิธีผสานรวมรีวิวในแอปในแอปของคุณโดยใช้ Kotlin หรือ Java หากคุณใช้โค้ดเนทีฟ, Unity หรือ Unreal Engine จะมีคำแนะนำในการผสานรวมแยกต่างหาก
ตั้งค่าสภาพแวดล้อมในการพัฒนาซอฟต์แวร์
ไลบรารีการขอรีวิวในแอปของ Play เป็นส่วนหนึ่งของไลบรารี Google Play Core รวมการขึ้นต่อกันของ Gradle ต่อไปนี้เพื่อผสานรวมไลบรารีการแจ้งขอรีวิวในแอปของ Play
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") ... }
สร้าง 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 ReviewException).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 = ((ReviewException) 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. });
ขั้นตอนถัดไป
ทดสอบโฟลว์การแจ้งให้รีวิวในแอปของแอปเพื่อยืนยันว่าการผสานรวมทำงานได้อย่างถูกต้อง