DEV Community

Cover image for Google Play In-App Review API to grow your app ratings
Rishabh Kumar
Rishabh Kumar

Posted on • Originally published at codewithrish.com

Google Play In-App Review API to grow your app ratings

Intro

Once we publish our app in Google PlayStore and it's live for users to download, app reviews and rating is very crucial for your apps to rank and stand out from the competition. We usually put some buttons of popups in apps to redirect users to PlayStore to get ratings and reviews. Now there is a great chance that users won't come back to the app. To overcome this problem google came up with a pretty good solution named In-App Review. This API helps us to show rating popup in our app itself so, the users don't have to leave your application.

Must know before implementation

  • In-App Review API supports minimum API level 21.
  • The API itself decides how often the review popup will be shown. We should now call it very often because there is a limited quota it won't show after that.
  • The review flow is also controlled by API itself. We should not try to alter that. Follow design guidelines for API
  • The review flow doesn’t indicate whether the user has reviewed our app or not, also it doesn’t tell us anything about what the review widget has shown to the user or not.

Let's Integrate In-App Review API

Add the following dependencies in your App Level Gradle file.

//  Play core library
implementation 'com.google.android.play:core:1.10.3'

Enter fullscreen mode Exit fullscreen mode

Open Main Activity

Now we will create an instance of the ReviewManager interface, which will help us to start our review dialog. After creating an instance we will call the requestReviewFlow() method which will return an object of ReviewInfo class on successful completion. Now with the help of the ReviewInfo class, we gonna call launchReviewFlow() method. Hurray we just created a complete flow of In-App Review API

Now let's see how it looks like in real code.

Code Snippet

import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.play.core.review.ReviewInfo;
import com.google.android.play.core.review.ReviewManager;
import com.google.android.play.core.review.ReviewManagerFactory;
import com.google.android.play.core.tasks.Task;

public class MainActivity extends AppCompatActivity {

    private ReviewManager reviewManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Initialize reviewManager 
        init();
    }

    // Initializing method for reviewManager
    private void init() {
        reviewManager = ReviewManagerFactory.create(this);
        // Initializing button and setting click listener using lambda method
        findViewById(R.id.rateApp).setOnClickListener(rate -> showRateApp());
    }


    // Shows the app rate dialog box using In-App review API
    // The app rating dialog flow might or might not be shown depending on the quota limitation
    public void showRateApp() {
        Task <ReviewInfo> request = reviewManager.requestReviewFlow();
        request.addOnCompleteListener(task -> {
            if (task.isSuccessful()) {
                // Create ReviewInfo object instance
                ReviewInfo reviewInfo = task.getResult();

                // Calling launch method with reviewManager and pass context and reviewInfo as required parameter
                Task <Void> flow = reviewManager.launchReviewFlow(this, reviewInfo);
                flow.addOnCompleteListener(task1 -> {
                    // The flow has finished. The API does not indicate whether the user
                    // reviewed or not, or even whether the review dialog was shown.
                });
            }
        });
    }
}

Enter fullscreen mode Exit fullscreen mode

Top comments (0)