Well Congratulations because you have coded, debugged and now published you app. The app itself is being used around the world by everyone but unfortunately that is not the end of the road for the application. Now that app is published the new objective is now collecting feedback and producing new updates which is accomplished by taking users feedback. An app rating and reviews are crucial factor to keep your app alive and have the downloads keep going. In the past the user would be prompted with a dialog with fancy buttons and upon ‘click’ the user is redirected to the Play Store. If the end user is anything like me, I find it annoying and complicated for the whole transition. Fear not Google understood and provided and API, which provide a rating widget in the app itself and the end user never has to leave the app itself.
Keep In Mind
- This API only functions with Android 5(API level 20+)
- The API is subject to quotas. Also the API decides how often the review widget should be shown to user.
- Note: More about quotas
- The flow process is controlled by the API. As the developer/designer you should not waste your time trying to alter the design.
- Note: More about Design Guidelines
- Furthermore the flow doesn’t notify us if the end user has completed the review or not
Integrating the API
Simple task here and can be accomplished with very little or minimal code. So enough talk and more implementing:
Since this API is apart of the Play Core API, so we need to add it to the library within the buid.gradle. In the code below you will notice that I am including the material library because I want to show a fallback if there is any error in-app review API.
//build.gradle dependencies { implementation 'androidx.appcompat:appcompat:1.3.0' implementation 'com.google.android.material:material:1.5.0' //optional material library implementation 'com.google.android.play:core:1.10.3' //play core library implementation 'androidx.constraintlayout:constraintlayout:2.0.4' testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' }
Now that has been accomplished, we need to create an instance of ReviewManager. This class provides necessary methods to start the review flow.
- New instance created, now a call the requestedReviewFlow() task returns ReviewInfo upon successful completion
- ReviewInfo object , needs to call launchReviewFlow() method which begins the review flow
- If requestReviewFlow fails, then we launch the usual Rate App dialog which then redirects the user to the Play Store.
- showRateApp() method starts the in-app review flow. The showRateAppFallbackDialog() method then acts as a fallback method if requestedReviewFlow throws an error.
package com.programmingninja.inappreview; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; 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 rm; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); doInit(); } private void doInit() { rm = ReviewManagerFactory.create(this); findViewById(R.id.btn_rating).setOnClickListener(view -> showRateApp()); } public void showRateApp() { Task<ReviewInfo> request = rm.requestReviewFlow(); request.addOnCompleteListener(task -> { if (task.isSuccessful()) { //reviewinfo object ReviewInfo ri = task.getResult(); Task<Void> flow = rm.launchReviewFlow(this, ri); flow.addOnCompleteListener(task1 -> { }); } else { // showRateAppFallbackDialog(); } }); } private void showRateAppFallbackDialog() { new MaterialAlertDialogBuilder(this) .setTitle(R.string.app_title) .setMessage(R.string.app_user_message) .setPositiveButton(R.string.app_btn_positive, (dialog, which) -> { }) .setNegativeButton(R.string.app_btn_negative, (dialog, which) -> { }) .setNeutralButton(R.string.app_btn_neutral, (dialog, which) -> { }).show(); } }
Install, Test, Conclude
To test the this action, you should have the app approved and published within the PlayStore. Don’t worry the app doesn’t need to be available to the public.