Skip to content
Related Articles

Related Articles

How to Integrate In-App Review API into Android App?
  • Last Updated : 18 Feb, 2021

Once we publish our app over the PlayStore and as it became live there, app rating and reviews become very crucial to driving audience and downloads to your app. In order to increase this, we ask our users to rate the app through a popup window and redirecting them to the PlayStore. But this nowadays creates little problems, once users went to PlayStore they might not come back to our app. To overcome this issue Google provides an API called In-App Review to show the rating popup in the app itself so, the users don’t have to leave the application. 

Points Regarding In-App Review API

  1. In-App Review is supported over the devices having Android 5(API level 21) or higher and have google PlayStore installed on the device.
  2. The API itself decides how often the review widget should be shown to the user, we should not call this API frequently as once a user reaches its maximum limit, the widget should not be shown to the user otherwise this may impact the user experience.
  3. The review flow is being controlled by the API itself, we shouldn’t try to alter its design.
  4. The review flow doesn’t indicate that 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.

Step By Step Implementation

Step 1: Creating A New Project

To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that select Java as the programming language.

Step 2: Adding Dependency 

In-App Review API is a part of Play Core API. In order to use In-App Review API in our app, we need to add the dependency of Play Core API. Go to Gradle Scripts > build.gradle(Module: app) and add the following dependencies. After adding these dependencies you need to click on Sync Now



dependencies {

 implementation “com.google.android.play:core:1.8.0”

}

Step 3: Working with the MainActivity.java file

In this step, we will create an instance of the ReviewManage interface, which provides the necessary methods to start the review flow. Once the instance is created we need to call the requestReviewFlow() method which returns the ReviewInfo object on successful completion. Using the ReviewInfo object we call the launchReviewFlow() method to start the review flow.

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);
  
        // Calling init() method
          // for initialization
        init();
    }
      
    // Initializing method
    private void init() {
        reviewManager = ReviewManagerFactory.create(this);
        // Referencing the button
        findViewById(R.id.rateBtn).setOnClickListener(view -> showRateApp());
    }
  
      
    // Shows the app rate dialog box using In-App review API
    // The app rate dialog box might or might not shown depending
      // on the Quotas and limitations
    public void showRateApp() {
        Task <ReviewInfo> request = reviewManager.requestReviewFlow();
        request.addOnCompleteListener(task -> {
            if (task.isSuccessful()) {
                // Getting the ReviewInfo object
                ReviewInfo reviewInfo = task.getResult();
  
                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.
                });
            }
        });
    }
}

Step 4: Testing In-App Review

In order to test In-App Review, your application must have already approved by PlayStore. It doesn’t require the app to be publicly available but at least you should have a PlyaStore Account for Internal Testing(used for releasing the track and test In-App Review flow) or Internal App Sharing(used for testing In-App Review flow). You can find a sample image for In-App Review.

Want a more fast-paced & competitive environment to learn the fundamentals of Android?
Click here to head to a guide uniquely curated by our experts with the aim to make you industry ready in no time!
My Personal Notes arrow_drop_up
Recommended Articles
Page :