In-App Review Android Implementation in Kotlin

In-App Review Android Implementation in Kotlin

As soon as the review for the app comes to mind, you worry about going to the Playstore, correct?
A review is an integral part that lets the developer know how much the users are enjoying their application. However, users generally do not review many apps because they do not want to go to the Play Store every time just to read a review.

But you, as a developer, want users to give ratings and feedback on your application.
So in order to solve this pain of users giving feedback from Playstore, Google developed an In-App Review API for letting users give their feedback directly within the app.

So lets quickly jump into the coding of this. It’s very easy to implement but the testing is quite a pain if you are a new developer.

Step 1: Add the Play core dependency in your build.gradle file.

implementation 'com.google.android.play:core:1.10.3'

Step 2: Now in your Activity

class MainActivity: AppCompatActivity() {

    private var reviewManager : ReviewManager? = null
    private var reviewInfo : ReviewInfo? = null

    override fun onCreate(savedInstanceState : Bundle?) {
        super.onCreate(savedInstanceState)
        binding = DataBindingUtil.setContentView(this,                   R.layout.activity_main)
reviewManager = ReviewManagerFactory.create(this)
                val request : Task<ReviewInfo> = reviewManager!!.requestReviewFlow()
                request.addOnCompleteListener { task ->
                    if (task.isSuccessful) {
                        // We can get the ReviewInfo object
                        reviewInfo = task.result
                    } else {
               // There was some problem, continue regardless of the result.
                    }
                }
 }
// Just to test on some button click show the app review dialog.
                btnClick.setOnClickListener(object : OnClickListener() {
                    fun onClick(v : View?) {
                        val flow = reviewManager!!.launchReviewFlow(this@MainActivity, reviewInfo!!)
                        flow.addOnCompleteListener { task : Task<Void?>? -> }
                    }
                })
     }
}

Note: The ReviewInfo object is only valid for a limited amount of time. Your app should request a ReviewInfo object ahead of time (pre-cache), but only once you are certain that your app will launch the in-app review flow.

Note: It is not suggested to show the app review dialog on a button click. Please read the guidelines here.

That’s it. The coding part is completed.

Key points to remember:

  • If you are using the Internal Sharing app to test this, you won’t be able to submit the review. The submit button is disabled 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 users who have already given the ratings on the play store. To test at your end, delete the review from the play store and it will show up.

  • Sometimes, 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.

More information will be available on the below official page:
https://developer.android.com/guide/playcore/in-app-review#when-to-request

Mansi Vaghela LinkedIn Twitter Github Youtube