How to implement Rate It feature in Android App

前端 未结 14 1382
囚心锁ツ
囚心锁ツ 2020-12-02 04:19

I am developing an Android App. In which everything is working right. My app is ready to launch. But there I need to implement one more feature. I need to display a popup wh

14条回答
  •  星月不相逢
    2020-12-02 04:48

    Java & Kotlin solution (In-app review API by Google in 2020):

    First, in your build.gradle(app) file, add following dependencies (full setup here)

    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:core:1.8.0'
    }
    

    Add this method to your Activity:

    void askRatings() {
        ReviewManager manager = ReviewManagerFactory.create(this);
        Task request = manager.requestReviewFlow();
        request.addOnCompleteListener(task -> {
            if (task.isSuccessful()) {
                // We can get the ReviewInfo object
                ReviewInfo reviewInfo = task.getResult();
                Task flow = manager.launchReviewFlow(this, reviewInfo);
                flow.addOnCompleteListener(task2 -> {
                    // 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.
                });
            } else {
                // There was some problem, continue regardless of the result.
            }
        });
    }
    

    Call it like any other method:

    askRatings();
    

    Kotlin code can be found here

提交回复
热议问题