Improve App Rating with Google In-App Review Dialog

When app developers publish apps on stores like Google Play or App Store etc., their apps are given reviews by users. These reviews are an important part that lets the developer know how much the users are enjoying their app. But users often don’t submit reviews of apps on Google Play due to either laziness to go to store or lack of awareness of how to review app. To help with this pain of users giving feedback from Play store, Google has developed an In-App Review API for letting users give their feedback directly within the app.

Cool, isn’t it? Let’s dig into it and see how you can integrate in your apps.



It should be noted here that In-App Review API only works on devices which have Android 5.0 (API level 21) or later and have Google Play Store installed. So, devices with custom Android OS or Huwaie phones will not support this API.

First you have to import the Play Core Library into your Android project as a Gradle dependency:

implementation "com.google.android.play:core:1.8.0"

Once the Play Core is added in your project, we will create the instance of ReviewManager using ReviewManagerFactory. The ReviewManager provides us the flow we need for showing the Google Play In-App review dislog inside the app.

val reviewManager = ReviewManagerFactory.create(this)

Google has provided some guidelines about when the app can ask for the review. So, to see if the app is eligible to show the In-App review dialog, you first need to request the review by calling requestReviewFlow(). This method communicates with the Google Play Store remotely and will give you an object of ReviewInfo to tell if the app can show the dialog or not. But remember that your app can’t access this information. It even will not know if the dialog was shown or user rated it or not. This is a designed behavior to make sure that there’s no misuse of the API to manipulate users to give app ratings.

val request: Task<Review Info?> = reviewManager.requestReviewFlow()
request.addOnCompleteListener { task ->
    if (task.isSuccessful) {
        // We got the ReviewInfo object
        val reviewInfo = task.result
    } else {
        // There was some problem, log or handle the error code.
        @ReviewErrorCode val reviewErrorCode = (task.getException() as TaskException).errorCode
    }
}

Now keeping the reference of the ReviewInfo object, we can start and maybe show the review dialog to the user.

if (reviewInfo != null) {
       val reviewflow = reviewManager!!.launchReviewFlow(this, reviewInfo!!)
       reviewflow.addOnCompleteListener {
           Toast.makeText(
               applicationContext,
               "In App Rating complete",
               Toast.LENGTH_LONG
           ).show()
       }
   } else {
       Toast.makeText(applicationContext, "In App Rating failed", Toast.LENGTH_LONG).show()
   }
}

One important thing to note here is that when flow is finished, the API does not indicate whether the user reviewed the app or not, or even whether the review dialog was shown. Thus, no matter the result, you need to continue your app flow as normal. If an error occurs during the in-app review flow, do not inform the user or change your app’s normal user flow. Continue your app’s normal user flow after onComplete is called.

Here’s the final code to request an In-App review dialog as discussed above:

class MainActivity : AppCompatActivity() {
 
   var reviewManager: ReviewManager? = null
   var reviewInfo: ReviewInfo? = null
 
   override fun onCreate(savedInstanceState: Bundle?) {
       super.onCreate(savedInstanceState)
       setContentView(R.layout.activity_main)

       getReviewInfo();
       
       someButton.setOnClickListener {
           startReviewFlow()
       }
   }
 
   /**
    * Call this method at app start etc to pre-cache the reviewInfo object to use to show 
    * in-app review dialog later.
    */
   private fun getReviewInfo() {
       reviewManager = ReviewManagerFactory.create(applicationContext)
       val manager = reviewManager?.requestReviewFlow()
       manager?.addOnCompleteListener { task: Task<ReviewInfo?> ->
           if (task.isSuccessful) {
               reviewInfo = task.result
           } else {
               Toast.makeText(
                   applicationContext,
                   "In App ReviewFlow failed to start",
                   Toast.LENGTH_LONG
               ).show()
           }
       }
   }
   
   /**
    * Call this method when you want to show the in-app rating dialog
    */
   fun startReviwFlow() {
       if (reviewInfo != null) {
           val flow = reviewManager!!.launchReviewFlow(this, reviewInfo!!)
           flow.addOnCompleteListener {
               Toast.makeText(
                   applicationContext,
                   "Rating complete",
                   Toast.LENGTH_LONG
               ).show()
           }
       } else {
           Toast.makeText(applicationContext, "Rating failed", Toast.LENGTH_LONG).show()
       }
   }
}

And this is how it will look like if app shows the In-App review dialog

Image Credits: https://developer.android.com/guide/playcore/in-app-review Image Credits: https://developer.android.com/guide/playcore/in-app-review

KEY POINTS TO REMEMBER

  • If you are using an internal sharing app to test this, you won’t be able to submit a review because Google doesn’t allow in this case.
  • After you have successfully tested it, remove your email from the Internal App Testers list to get the actual Public Review Dialog. Otherwise, you would always get a Private Review.
  • The app review dialog won’t show to user who already have given the rating on play-store. To test this case, delete the review from the play store, and see if it shows up again or not.
  • Sometimes, the dialog won’t even show up, because of the quota limit of launchReviewFlow. See here for more info.
  • You should not depend on the dialog to show up, and then you do your remaining work because you don’t get any callback whether the user has given the feedback or not.

What’s Next?

I hope you understood the concept of how Google In-App Review API and dialog works. I would love to hear your feedback, so leave a comment below and share with others!

At the end, please Subscribe to my newsletter DroidUp to learn learn about the latest things, tips, and skills in Android development manually handcrafted and curated by Wajahat Karim.


If you liked this article, you can read my new articles below:


profile card
Wajahat Karim
🌍 Making the world a better place, one app at a time.
🔥 Google Developer Expert (GDE) in Android . 📱 Professional Android Developer with ~10 years experience. 💻 Creator of various Open Source libraries on Android . 📝 Author of two technical books and 100+ articles on Android. 🎤 A passionate Public Speaker giving talks all over the world.
Author's picture

Wajahat Karim

🔥 Google Dev Expert (GDE) in Android .
📱 Android Dev. 💻 Open Source Contributor . 📝 Technical Writer . 🎤 Public Speaker

Senior Android Developer

Karachi, Pakistan