avatarVincent Tsen

Summary

The web content provides a comprehensive guide on implementing the Google Play In-app Review API within an Android app, including the necessary library additions, code examples, and a method for testing the feature through Internal App Sharing.

Abstract

The article "How to add Google Play In-app Review Dialog?" offers a step-by-step tutorial on integrating Google Play's In-app Review API into an Android application. It begins by illustrating the appearance of the in-app review dialog and advises developers to initiate the review process from an activity rather than a composable function for best practices. The guide includes the necessary dependencies for the build.gradle.kts file, demonstrates how to create and use a ReviewManager instance, and provides a function to trigger the review dialog. It also discusses the importance of handling the API's quotas and the lack of callbacks to confirm dialog display. For testing purposes, the article recommends using Internal App Sharing via the Google Play Console, detailing the steps to enable this feature for testers. The conclusion acknowledges the simplicity of implementing the in-app review but notes the complexity of deciding when to prompt users for reviews, suggesting a possible strategy based on the app's installation age.

Opinions

  • The author emphasizes that implementing the in-app review dialog is straightforward but cautions against triggering it in a way that could lead to a broken user flow.
  • It is noted that the in-app review API has quotas on how often it can be called, and the dialog will not appear if the user has already reviewed the app or if the quota has been reached.
  • The article suggests that deciding when to prompt users for a review can be challenging, especially for simple apps, and proposes delaying the prompt for a certain period after installation as a potential solution.
  • The author provides an example of how to calculate the time since the app's first installation to inform the decision of when to trigger the in-app review.
  • The lack of callbacks to indicate whether the review dialog has been shown is seen as a drawback, potentially leaving users with a non-functional "Rate Me" option.
  • The use of Internal App Sharing for testing the in-app review feature is recommended for its ease and the ability to bypass the API's quota limitations during testing, although the submit button will be disabled in this mode.

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

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)
            }
        }
    }
    /*...*/
}

Then, set this function to be a callback from your composable function.

override fun onCreate(savedInstanceState: Bundle?) {
    /*...*/
    setContent {
        /*...*/
        MainScreen(showReviewDialog = ::showReviewDialog)
    }
}

What I did is simply add a drop-down “Rate Me” menu to the app.

Well, this is for educational purposes and is not recommended to implement this way because there are no callbacks to indicate whether Google Play review dialog is shown or not. If the dialog is not shown (for the reasons below), this appears to be a broken user flow, which we want to avoid!

There are quotas on how many times this API can be called. Clicking the “Rate Me” the second time, won’t show the Google Play review dialog anymore. I also noticed if you have already reviewed the app, call the ReviewManager.launchReviewFlow() API does nothing too.

For more information, you can refer to the official document here.

4. Test In-app Reviews

The issue is you can’t test it in your emulator directly because it requires your app to be published in Play Store.

There are a few ways you can test it out (as you can read from the documentation here) but the easiest way in my opinion is internal app sharing.

Here are the steps to upload your app for internal app sharing:

  1. In Google Play Console, go to Setup -> Internal App Sharing
  2. Create an Internal Testers email lists. Separate the emails with a comma.

3. In Manage testers, select Restrict access to email lists

4. In Manage uploaders, click this link, https://play.google.com/console/internal-app-sharing. After that, you can upload your app bundle or APK here.

5. Copy the link and sent it to your testers (it could be yourself). The tester needs to open the link on his/her phone and it looks like this. Click OPEN IN PLAY STORE APP.

6. You get this if your Google Play has not enabled Internal app sharing. Click the Google Play Settings.

7. In Google Play Settings, go to About, and click Play Store Version 7 times. This enables the developer options.

8. Go to General -> Developer options, and enable the Internal app sharing. You get this prompt, so just click Turn on.

9. Go back to step 5, and click OPEN IN PLAY STORE APP again. It brings you to Google Play Store, to install the app.

If the app has already been installed previously, it asks you to uninstall it first.

10. Now, you should be able to test the Google Play In-App Review Dialog.

In this testing mode, the quotas do not apply here. You can call this Google Play In-App review API as many times as you wish. The only thing is the Submit button is disabled.

Conclusion

Implementing the Google Play in-app review dialog is quite simple, but testing is a bit tricky. It will be nice if we can test it out directly from the emulator.

Deciding when to trigger the in-app review is also a bit tricky for a very simple app like this one. Unlike games after the player finished a level, you can trigger in-app reviews.

Maybe I can do something like prompting the in-app review after the user installed the app after a certain period? Yeah, I will do that next.

[Updated — July 09, 20 23]: This is an example of getting the duration after the app was first installed using PackageInfo.firstInstallTime from PackageManager.

class MainActivity : ComponentActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        showReviewDialog()
        super.onCreate(savedInstanceState)
        /*...*/
    }

    private fun showReviewDialog() {        
        val packageInfo = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
            packageManager.getPackageInfo(packageName, PackageManager.PackageInfoFlags.of(0))
        } else {
            packageManager.getPackageInfo(packageName, 0)
        }

        val installTime = packageInfo.firstInstallTime
        val currentTime = System.currentTimeMillis()
        val durationInMillis = currentTime - installTime
        val durationInDays = durationInMillis / (1000 * 60 * 60 * 24)
        /*...*/
    }
}

Example

GitHub Repository: AndroidNews

Originally published at https://vtsen.hashnode.dev.

AndroidDev
Android App Development
Google Play Review
Review Manager
Android
Recommended from ReadMedium