Uygulama içi yorumları entegre edin (Kotlin veya Java)

Bu kılavuzda, Kotlin veya Java. Yerel reklamlar kullanıyorsanız ayrı entegrasyon kılavuzları vardır kodu veya Unity.

Geliştirme ortamınızı ayarlama

Play Uygulama İçi İnceleme Kitaplığı, Google Play Core kitaplıklarının bir parçasıdır. Play Uygulama İçi'ni entegre etmek için lütfen aşağıdaki Gradle bağımlılığını ekleyin Yorum Kitaplığı'nı tıklayın.

Eski

// 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")
    ...
}

İnceleme Yöneticisi'ni oluşturma

ReviewManager uygulamanızın uygulama içi inceleme akışı başlatmasını sağlayan arayüzdür. Edinme tarihi ReviewManagerFactory kullanarak örnek oluşturabilirsiniz.

Kotlin

val manager = ReviewManagerFactory.create(context)

Java

ReviewManager manager = ReviewManagerFactory.create(context)

ReviewInfo nesnesi isteme

Ne zaman uygulama içi istekte bulunacağınızla ilgili talimatları uygulayın. incelemeden yararlanarak iyi puanları kullanıcının inceleme yapmasını istemek için (örneğin, Kullanıcı oyunda bir seviyeyi tamamladığında). Uygulamanız bu noktalardan birine ulaştığında ReviewManager bağlantısını kullanın. istek görevi oluşturun. Başarılı olursa API, ReviewInfo nesne başlatmamız gerekir.

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

Uygulama içi inceleme akışını başlatma

ReviewInfo'ı kullanma uygulama içi inceleme akışını başlatmak için kullanılır. Kullanıcı şu işlemi tamamlayana kadar bekleyin: uygulamanız normal kullanıcı akışına devam etmeden önce (ör. ilerlemeyi gösterebilirsiniz.

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

Sonraki adımlar

Uygulamanızın uygulama içi inceleme akışını test ederek entegrasyonunuzun düzgün çalıştığını doğrulayın.