In-App Review- A wanted feature

Glitch
3 min readJun 19, 2021

--

As an android developer, we always want good ratings from the users. It is because Google play store rating plays a crucial role in the app’s popularity. The question is how do you ask your user to rate the app?

The most used approach is by showing a popup and redirect the user to the play store. It makes a negative impact because the user has to leave the app and what is a possible chance that he will come back ?. It makes a bad user experience.

Integrating In-App Review API

Integrating In-App review is very simple. It can be achieved with very minimal code. Let’s see how to integrate it.

1. The In-App review API is part of Play Core API, so you have to include the library in your app’s build.gradle. Here I am adding a material library as well as I want to show a fallback rating dialog if there is an error in the in-app review API.

app/build.gradle

app/build.gradle
// Play core library
implementation "com.google.android.play:core:1.8.0"

// optional material library to show the fallback rate us dialog
implementation "com.google.android.material:material:1.3.0-alpha02"

2. The next step is creating the instance of the ReviewManager interface. This class provides the necessary methods to start the review flow.

  • Once the new instance is created, we need to call the requestReviewFlow() task which returns the ReviewInfo object upon successful completion.
  • Using the ReviewInfo object, we need to call the launchReviewFlow() method to start the review flow.
  • For some reason, if the requestReviewFlow fails, we can launch the usual Rate App dialog that redirects users to play store app.
  • Below, the showRateApp() method starts the in-app review flow. The showRateAppFallbackDialog() method acts as a fallback method if requestReviewFlow throws an error. This fallback method shows the usual material dialog with three buttons to redirect the user to the playstore app.

Here is the complete code 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());
}

/**
* Shows rate app bottom sheet using In-App review API
* The bottom sheet might or might not shown depending on the Quotas and limitations
* https://developer.android.com/guide/playcore/in-app-review#quotas
* We show fallback dialog if there is any error
*/
public void showRateApp() {
Task<ReviewInfo> request = reviewManager.requestReviewFlow();
request.addOnCompleteListener(task -> {
if (task.isSuccessful()) {
// We can get 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. Thus, no
// matter the result, we continue our app flow.
});
} else {
// There was some problem, continue regardless of the result.
// show native rate app dialog on error
showRateAppFallbackDialog();
}
});
}

/**
* Showing native dialog with three buttons to review the app
* Redirect user to playstore to review the app
*/
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();
}
}

Testing In-App Review Flow

To test the in-app review flow, you should have the app approved already on PlayStore. This doesn’t mean the app should be available to the public. At least you should have the account ready for Internal Testing or Internal App 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.

Ta-da!! Thus we added one more cool feature to our app.Keep Coding!!

--

--

No responses yet