How To Add Google In-App Review for Android

Android Development
February 11, 20222 minutesuserVivek Beladiya
How To Add Google In-App Review for Android

Integrating in-app reviews is very easy. It can be achieved with very minimal code. Let's see how to integrate it.

1. As the In-App Review is a part of the Play core library, we need to add the required dependencies to our app's build.gradle (app level) file,

implementation “com.google.android.play:core:1.8.0”
implementation "com.google.android.material:material:1.3.0-alpha02"

2. First, we need to create the instance of ReviewManager which would help us to start the API. We create the instance using,

ReviewManager manager = ReviewManagerFactory.create(this);

Now, using this manager object, we have to request the flow to launch the In-App review flow.

 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, continue regardless of the result.
      }
 });

A complete code is required for the in-app review flow.

MainActivity.java
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);
       init();
   }

   private void init() {
       reviewManager = ReviewManagerFactory.create(this);
       findViewById(R.id.btn_rate_app).setOnClickListener(view -> showRateApp());
   }

   public void showRateApp() {
       Task<ReviewInfo> request = reviewManager.requestReviewFlow();
       request.addOnCompleteListener(task -> {
           if (task.isSuccessful()) {
               ReviewInfo reviewInfo = task.getResult();
               Task<Void> flow = reviewManager.launchReviewFlow(this, reviewInfo);
               flow.addOnCompleteListener(task1 -> {
               });
           } else {
               showRateAppFallbackDialog();
           }
       });
   }
   private void showRateAppFallbackDialog() {
       new MaterialAlertDialogBuilder(this)
               .setTitle(R.string.rate_app_title)
               .setMessage(R.string.rate_app_message)
               .setPositiveButton(R.string.rate_btn_pos, (dialog, which) -> {

               })
               .setNegativeButton(R.string.rate_btn_neg,
                       (dialog, which) -> {
                       })
               .setNeutralButton(R.string.rate_btn_nut,
                       (dialog, which) -> {
                       })
               .setOnDismissListener(dialog -> {
               })
               .show();
   }
}

How to test the In-App Review?

To check the in-app review flow, you must already have the app approved on Playstore. This does not mean that the application should be available to the public. At the very least, you should have an account ready for internal testing or internal application sharing.

  • You can use Internal Test Track to release the app and test the in-app review flow.
  • You can use Internal App Sharing to test the in-app review flow.

You can find more information about the test part on the Android Developer page.