Google Play Store Rating & ReviewAPI
Published: 2023-04-22 18:51:18

Google announced an in-app review API that prompts users to submit Play store ratings and reviews without leaving the application and without opening the Play store either. Before it we show the dialog and for rating we move to play store app for rating and review which distract user from application. But for new Review API User can give rating and review without moving to play store and Users’ reviews/ratings will eventually be displayed in the Google Play store.

This encourages users to give feedback on your application.

[](https://miro.medium.com/v2/resize:fit:640/format:webp/1*GnCq9l24YXltZflCW-dWlQ.png)

Typically, this API concept is a better way of asking users for a review than the fallback rate dialog.

**What are the benefits of integrating Google Play In-App Review API**
There are two major flaws in the earlier setup for getting Play store ratings and reviews from users:

1. Users are prompted to rate the app, with an in-app survey and if the user hits the 5 stars, then the user is asked to rate the app in play store. Most of the users do not want to put the effort of rating twice, no matter how much they love your app.

2. The other flaw in the setup is that the users need to navigate out of the app to give the ratings. Which is also not really desirable.‍

With the In-App Review API, both of these flaws are countered. You don’t need to prompt users twice for the ratings, nor do they need to navigate out of the app to give the ratings and reviews.

**How to implement Review & Rating API**
Device Requirements:

> You can use In-App Reviews in Android devices (phones and tablets) running Android 5.0 (API level 21) or higher that have the Google Play Store installed.

**Integration
Step 1: Adding dependency**
Add Google Core Library to your build.gradle file.
`

```
implementation 'com.google.android.play:core:1.9.0'
```
`
Sync to download the library to have access to the necessary classes to initiate review flow.

Always ensure that you are using the latest library version. Check here for newly added versions.

**Step 2: Creating an instance of a ‘ReviewManager’**

The ReviewManager provides the required functions that trigger the review flow.

They include:

requestReviewFlow() — fetches application information from the Play store.
launchReviewFlow() — initiates the review flow.
Declare ReviewManager right above onCreate().

To create an instance of ReviewManager:

1. Declare ReviewManager right above onCreate().
2. Use ReviewManagerFactory calling the create function, and pass your application context to it.

`

```
reviewManager = ReviewManagerFactory.create(getApplicationContext());
```
`
**Step 3: Requesting review info**
requestReviewFlow() communicates with the Google Play store remotely to get the information that references your application.

Declare ReviewInfo.

ReviewInfo reviewInfo;
ReviewInfo holds this information, that will be used to trigger the review flow process to the end user.

`

```
Task<ReviewInfo> manager = reviewManager.requestReviewFlow();
        manager.addOnCompleteListener(task -> {
            if (task.isSuccessful()) {
                reviewInfo = task.getResult();
            } else {
            }
        });

```
`

Calling requestReviewFlow() will return the data associated with your play store application. This function performs an asynchronous operation, meaning we have to wait for the operation to complete.

For this reason, we need to assign a listener. The listener will let ReviewManager know when the Task is completed and assign the request’s results to ReviewInfo.

**Step 4: Launching ReviewFlow**

Referencing the ReviewFlow, we can start and show the review dialog to the user. However, in some instances, requestReviewFlow() can fail to get the application information, meaning that ReviewFlow will be null.

These instances include:

Poor internet connection.
A user has previously written a review for your application.
Quota restriction. Due to the quota imposed by this API, not every request will be successful.
For this reason, we need to start launchReviewFlow() if ReviewFlow is not null. Make sure you assign ReviewFlow to null.

ReviewInfo reviewInfo = null;
When null, the ReviewManager will terminate the review flow.

`

```
if (reviewInfo != null) {
    Task<Void> flow = reviewManager.launchReviewFlow(this, reviewInfo);
    flow.addOnCompleteListener(new OnCompleteListener<Void>() {
        @Override
        public void onComplete(Task<Void> task) {
            Toast.makeText(getApplicationContext(), "In App Rating complete", Toast.LENGTH_LONG).show();
        }
    });
}
else {
}
```
`

When requestReviewFlow() is successful, ReviewFlow will be assigned to the request results. You need to check if reviewInfo != null to trigger the review flow with launchReviewFlow(). Then the API will handle the review’s comment and rating and update your application store listing showing them.

This API state’s that if an error occurs during the review flow, you should never inform the user or change your normal application flow. The app should continue its usual flow after onComplete is called.

Final code:

`

```
public class MainActivity extends AppCompatActivity {
    ReviewManager reviewManager;
    ReviewInfo reviewInfo = null;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        getReviewInfo();
    }

    private void getReviewInfo() {
        reviewManager = ReviewManagerFactory.create(getApplicationContext());
        Task<ReviewInfo> manager = reviewManager.requestReviewFlow();
        manager.addOnCompleteListener(task -> {
            if (task.isSuccessful()) {
                reviewInfo = task.getResult();
                startReviewFlow();
            } else {
                Toast.makeText(getApplicationContext(), "In App ReviewFlow failed to start", Toast.LENGTH_LONG).show();
            }
        });
    }

    public void startReviewFlow() {
        if (reviewInfo != null) {
            Task<Void> flow = reviewManager.launchReviewFlow(this, reviewInfo);
            flow.addOnCompleteListener(new OnCompleteListener<Void>() {
                @Override
                public void onComplete(Task<Void> task) {
                    Toast.makeText(getApplicationContext(), "In App Rating complete", Toast.LENGTH_LONG).show();
                }
            });
        }
        else {
            Toast.makeText(getApplicationContext(), "In App Rating failed", Toast.LENGTH_LONG).show();
        }
    }
}
```
`

**Testing**
To test our application, we will use internal app sharing. To confirm that this works, add a Button to trigger the review flow. Remember, we are using a call to action for testing. In production applications, calls to action such as Button should be avoided when using this API.

Create reference and manage OnClickListener and call startReviewFlow()

`

```
mButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        startReviewFlow();
    }
});
```
`
**How to test**

1. Generate a signed app bundle/APK. Note the APK signing key and the applicationId should be the same as the already published application.
2. Share the generated APK with a tester. To do that, select the published application in the Google console, navigate to Internal App Sharing, and upload the generated APK there. Check how to use Google Internal App Sharing.
3. Copy the upload’s shareable link and share it with a tester. In this case, a tester should be using an Android mobile phone.
4. Open the shared link on the phone’s browser. You will be prompted to open with the Google Play store. Do so. This will launch a Play store screen.
5. Download the app and wait for the installation to complete.
6. Launch the application and click SHOW IN APP REVIEW DIALOG to start the review flow, as shown in the image below.

**Note:**

1. Since we a carrying out a test, the submit button will be inactive.
2. If you have previously reviewed the application, delete your comment in the Google Play store. Otherwise, the review sheet won’t pop up.
3. For more reference, check the code of @Joseph chege on GitHub.
4. 
5. What is the best way to make use of Google Play In-App Review API
6. Standard Developer Guidelines to help you decide when to request in-app reviews from users:
7. 
8. Trigger the in-app review flow after a user has experienced enough of your app or game to provide useful feedback.
9. Do not prompt the user excessively for a review. This approach helps minimize user frustration and limit API usage.
10. Your app should not ask the user any questions before or while presenting the rating button or card, including questions about their opinion (such as “Do you like the app?”) or predictive questions (such as “Would you rate this app 5 stars”).
11. There is a cap on the number of times a user is shown the review dialog, and this is called Quota. This limit has been enforced by Google to ensure that user experience is not disrupted by a flood of such requests. Hence, as per guidelines, it’s not optimal to have a call-to-action mechanism to launch the in-app review.

**How In-App Review API works**
The in-app review flow can be triggered at any time throughout the user journey of your app. During the flow, the user has the ability to rate your app using the 1 to 5 star system and to add an optional comment. Once submitted, the review is sent to the Play Store and eventually displayed.

Check the documentation guidelines regarding when you should request the review flow.

The API states that you need to note the following:

How you ask for reviews matters. When using this API, you should not ask predictive or opinionated questions before or after the review sheet dialogs show the app in your application. These questions include:
Would you rate this application five stars?
Do you like this app?
2. The API also advises you only to show dialog once a user has enough. experience with your application. It’s not a good practice to ask a user to write a review before the app delivers value to that user. Chances are, the user will get annoyed and skip the review. And if they don’t skip it, they will give negative reviews.

3. In order to minimize API usage and avoid annoying users, it would be best if you did not excessively ask users to write reviews.

Thanks for the reading…