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

Bu kılavuzda, Kotlin veya Java kullanarak uygulama içi yorumları uygulamanıza nasıl entegre edeceğiniz açıklanmaktadır. Yerel kod, Unity veya Unreal Engine kullanıyorsanız ayrı entegrasyon kılavuzları mevcuttur.

Geliştirme ortamınızı ayarlama

Play Uygulama İçi Yorum Kitaplığı, Google Play Core Library'lerinin bir parçasıdır. Play Uygulama İçi Yorum Kitaplığı'nı entegre etmek için aşağıdaki Gradle bağımlılığını ekleyin.

Modern

// 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'ı oluşturma

ReviewManager, uygulamanızın uygulama içi yorum akışı başlatmasını sağlayan arayüzdür. ReviewManagerFactory kullanarak bir örnek oluşturarak elde edin.

Kotlin

val manager = ReviewManagerFactory.create(context)

Java

ReviewManager manager = ReviewManagerFactory.create(context)

ReviewInfo nesnesi isteme

Uygulamanızın kullanıcı işlemleri akışında kullanıcıdan yorum istemek için uygun noktaları (ör. kullanıcı bir oyunda seviye tamamladığında) belirlemek üzere uygulama içi yorumların ne zaman isteneceği ile ilgili yönergeleri uygulayın. Uygulamanız bu noktalardan birine ulaştığında bir istek görevi oluşturmak için ReviewManager örneğini kullanın. Başarılı olursa API, uygulama içi yorum akışını başlatmak için gereken ReviewInfo nesnesini döndürür.

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

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

Uygulama içi yorum akışını başlatmak için ReviewInfo örneğini kullanın. Uygulamanız normal kullanıcı işlemleri akışına (ör. bir sonraki seviyeye geçme) devam etmeden önce kullanıcının uygulama içi yorum akışını tamamlamasını bekleyin.

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

Sonraki adımlar

Entegrasyonunuzun doğru şekilde çalıştığını doğrulamak için uygulamanızın uygulama içi yorum akışını test edin.