คู่มือนี้อธิบายวิธีผสานรวมรีวิวในแอปไว้ในแอปโดยใช้ Kotlin หรือ Java เรามีคู่มือการผสานรวมแยกต่างหากหากคุณใช้โฆษณาเนทีฟ รหัส หรือ Unity
ตั้งค่าสภาพแวดล้อมในการพัฒนาซอฟต์แวร์
ไลบรารีการรีวิวในแอปของ Play เป็นส่วนหนึ่งของไลบรารีหลักของ Google Play โปรดระบุการอ้างอิง Gradle ต่อไปนี้เพื่อผสานรวม Play In-App คลังรีวิว
ดึงดูด
// 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.1' // For Kotlin users also add the Kotlin extensions library for Play In-App Review: implementation 'com.google.android.play:review-ktx:2.0.1' ... }
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.1") // For Kotlin users also import the Kotlin extensions library for Play In-App Review: implementation("com.google.android.play:review-ktx:2.0.1") ... }
สร้างเครื่องมือจัดการรีวิว
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. });
ขั้นตอนถัดไป
ทดสอบขั้นตอนการตรวจสอบในแอปเพื่อ ตรวจสอบว่าการผสานรวมทำงานได้อย่างถูกต้อง