How to add Google Play In-app Review Dialog?

A step-by-step guide how you can let users review your app using Google Play In-app review API and test it out using Internal App Sharing

Vincent Tsen

--

This is just a quick guide and a simple example of how to add the Google Play In-app review dialog in your app. This is what it looks like after I implemented this in RSS feed reader app.

1. Add Review API Libraries

This example of build.gradle.kts ( Kotlin script/KTS) in your app module.

dependencies {
/*...*/
implementation("com.google.android.play:review:2.0.1")
implementation("com.google.android.play:review-ktx:2.0.1")
/*...*/
}

2. Create ReviewManager in the Activity

It is better to implement the ReviewManger in activity rather than a composable function because its APIs needs an activity. Well, you can technically do it in composable function (through LocalContext), but it is not a good practice because composable functions shouldn't need to know about the activity.

This creates the ReviewManager using ReviewManagerFactory.create() API in your activity. Of course, only when it is accessed because of the lazy delegate is used here.

class MainActivity : ComponentActivity() {
/*...*/
private val reviewManager by lazy {
ReviewManagerFactory.create(this)
}
/*...*/
}

3. Add showReviewDialog() Function

Let’s create a function that requests the review flow and launch the review dialog.

class MainActivity : ComponentActivity() {
/*...*/
private fun showReviewDialog() {
val request = reviewManager.requestReviewFlow()
request.addOnCompleteListener { task ->
if (task.isSuccessful) {
val reviewInfo = task.result
reviewManager.launchReviewFlow(this, reviewInfo)
}
}
}
/*...*/
}

--

--