Android-How to Add In-App Review Google Play API in Android to Gain Users Ratings

Sovary May 9, 2022 3.33K
3 minutes read

When your app becomes live in PlayStore, You want more audience to download and use your app. Mostly they will look at your rating stars and review their comments which means the app rating and review become important in gain audience and downloads to your app.


Traditionally we have to implement some code in your app to redirect users into Google Playstore so that they can review your app. To improve more user-friendly, we encourage users to review or rate the app through a popup dialog Google Provide an API called in-App Review which displays the rating popup within the app itself, so the users are more likely to rate the app.

Pre-requisite

  • Android devices running Android 5.0 (API level 21) or higher and have the Google Play Store installed.
  • Use version 1.8.0 or higher of the Play Core library.
  • We should not access this API frequently once a user exceeds its maximum limit, the widget may not be displayed to the user. Read about Quotas for more detail.
  • The review flow is being controlled by the API itself, we shouldn’t try to alter its design.
  • The card review and the card’s background should be on the topmost layer.

Implementation

Step 1: Create a new project in Android Studio (File -> New -> Project -> Select Empty Activty -> Name project AppReviewTest -> Finish)

Step 2: Insert the Google Play Core Dependency to android build.gradle file (Module: app). Note: My latest play core version (video) was 1.10.3 but you can use the latest stable release you want from Play Core Library. (app -> build.gradle(Module: app))

implementation 'com.google.android.play:core:1.10.0'

Step 3: In this example, we will add a button to show the dialog review, but in case you apply in real project should not apply like this. Open the following to edit the layout (app -> res -> layout -> activity_main.xml)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/btn"
        android:text="Show"/>
</LinearLayout>

Step 4: Implement Java code in MainActivity.java. Open file the following (app -> java -> MainActivity.java)

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.Toast;
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 ReviewInfo reviewInfo;
    private ReviewManager manager;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        activateReviewInfo();
        Button btn = findViewById(R.id.btn);
        btn.setOnClickListener((view)->
        {
            startReviewFlow();
        });
    }
    void activateReviewInfo()
    {
        manager = ReviewManagerFactory.create(this);
        Task<ReviewInfo> managerInfoTask = manager.requestReviewFlow();
        managerInfoTask.addOnCompleteListener((task)->
        {
            if(task.isSuccessful())
            {
                reviewInfo = task.getResult();
            }
            else
            {
                Toast.makeText(this, "Review failed to start", Toast.LENGTH_SHORT).show();
            }
        });
    }
    void startReviewFlow()
    {
        if(reviewInfo !=null)
        {
            Task<Void> flow= manager.launchReviewFlow(this,reviewInfo);
            flow.addOnCompleteListener(task ->
            {
                Toast.makeText(this, "Rating is completed", Toast.LENGTH_SHORT).show();
            });
        }
    }
}

Testing In-App Review

To test the in-app review flow, you should have the app approved already live on PlayStore.
This doesn’t mean the app should be available to the public. You may add the app for Internal Testing or Internal App Sharing. To more understanding please check the video above to see all processes.

You might Also Like:

Android  Java  Video 
Author

Founder of CamboTutorial.com, I am happy to share my knowledge related to programming that can help other people. I love write tutorial related to PHP, Laravel, Python, Java, Android Developement, all published post are make simple and easy to understand for beginner. Follow him    

Search