שילוב ביקורות בתוך האפליקציה (Kotlin או Java)

במדריך הזה מוסבר איך לשלב ביקורות באפליקציה באמצעות Kotlin או Java. יש מדריכי הטמעה נפרדים אם אתם משתמשים בקוד מקורי, ב-Unity או ב-Unreal Engine.

הגדרת סביבת הפיתוח

ספריית הביקורות באפליקציה של Play היא חלק מספריות Google Play Core. כדי לשלב את ספריית Play In-App Review, צריך לכלול את התלות הבאה ב-Gradle.

מגניב

// 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)

בקשה לאובייקט Request a 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.
});

השלבים הבאים

בודקים את תהליך שליחת הביקורת באפליקציה כדי לוודא שההטמעה פועלת בצורה תקינה.