คู่มือนี้อธิบายวิธีผสานรวมรีวิวในแอปในแอปของคุณโดยใช้ Kotlin หรือ Java หากคุณใช้โค้ดแบบเนทีฟ, Unity หรือ Unreal Engine จะมีคู่มือการผสานรวมแยกต่างหาก
ตั้งค่าสภาพแวดล้อมในการพัฒนาซอฟต์แวร์
ไลบรารีรีวิวในแอปของ Play เป็นส่วนหนึ่งของไลบรารี Google Play Core รวมทรัพยากร Dependency ของ Gradle ต่อไปนี้เพื่อผสานรวมไลบรารีรีวิวในแอปของ Google Play
ดึงดูด
// 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) {
// 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()) {
// 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 doesn't indicate whether the user
// reviewed or not, or even whether the review dialog was shown. Thus, no
// matter the result, continue your app flow.
}
Java
Task<Void> flow = manager.launchReviewFlow(activity, reviewInfo);
flow.addOnCompleteListener(task -> {
// The flow has finished. The API doesn't indicate whether the user
// reviewed or not, or even whether the review dialog was shown. Thus, no
// matter the result, continue your app flow.
});
ขั้นตอนถัดไป
ทดสอบขั้นตอนการรีวิวในแอปของแอปเพื่อยืนยันว่าการผสานรวมทำงานได้อย่างถูกต้อง