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

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

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

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

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.
});

השלבים הבאים

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