In-App Review API is a long-awaited feature that Google has launched in August 2020 like Apple did in 2016 for iOS apps.
With this API users will review and rate an application without leaving it. Google suggestion to developers not to force users to rate or review all the time as this API allocate a quota to each user on the specific usage of the application in a time. Surely developers would not be able to interrupt users with an attractive pop-up in the middle of their task.
Java
In Application level (build.gradle)
dependencies {
// This dependency from the Google Maven repository.
// include that repository in your project's build.gradle file.
implementation 'com.google.android.play:core:1.9.0'
}
boolean isGMSAvailable = false;
int result = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(this);
isGMSAvailable = (com.google.android.gms.common.ConnectionResult.SUCCESS == result);
if(isGMSAvailable)
{
ReviewManager manager = ReviewManagerFactory.create(this);
Task<ReviewInfo> request = manager.requestReviewFlow();
request.addOnCompleteListener(task -> {
try {
if (task.isSuccessful())
{
// getting ReviewInfo object
ReviewInfo reviewInfo = task.getResult();
Task<Void> flow = manager.launchReviewFlow(this, reviewInfo);
flow.addOnCompleteListener(task2 -> {
// 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
// call old method for rating and user will land in Play Store App page
Utils.rateOnPlayStore(this);
}
} catch (Exception ex)
{
Log.e("review Ex", "review & rate: "+ ex);
}
});
}
else
{
// if user has not installed Google play services in his/her device you land them to
// specific store e.g. Huawei AppGallery or Samsung Galaxy Store
Utils.rateOnOtherStore(this);
}
Kotlin
val manager = ReviewManagerFactory.create(context)
val request = manager.requestReviewFlow()
request.addOnCompleteListener { request ->
if (request.isSuccessful) {
// We got the ReviewInfo object
val reviewInfo = request.result
} else {
// There was some problem, continue regardless of the result.
}
}
//Launch the in-app review flow
val flow = manager.launchReviewFlow(activity, reviewInfo)
flow.addOnCompleteListener { _ ->
// 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.
}
for Testing use FakeReviewManager
//java
ReviewManager manager = new FakeReviewManager(this);
//Kotlin
val manager = FakeReviewManager(context)