Google In-App Review Dialog
As soon as the developers publish apps on stores like Google Play or App Store, user reviews come into mind correct?
User feedback plays an important role that letting the development team know how much the users are enjoying their app and which part needs to be updated. However, users often don’t submit reviews of apps on Google Play due to either laziness in going to the store or lack of awareness of how to review apps. To overcome these challenges Google has developed an In-App Review API for letting users give their feedback directly within the app.
Cool, isn’t it? Let’s jump into the integration part and see how you can manage it in your apps.
Add the Play core dependency in your build.gradle file.
implementation ("com.google.android.play:core:1.10.3")
Now we will create the instance of ReviewManager using ReviewManagerFactory, It provides the flow to show the In-App review dialog inside the app.
val reviewManager = ReviewManagerFactory.create(this)
It is not suggested to just show the review dialog on a button click, Please review these guidelines about when the app can ask for a review provided by Google. To check the app eligibility to show the In-App review dialog, you first need to request the review by calling RequestReviewFlow(). This method directly communicates with the Google Play Store remotely and will provide you an object of ReviewInfo to confirm that if the app can show the dialog or not. But remember that your app can’t access this information. It will not even 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 you have an object of ReviewInfo, we can proceed to show the review dialog to the user.
if (::reviewManager.isInitialized) {
val flow = reviewManager.launchReviewFlow(this, reviewInfo)
flow.addOnCompleteListener {
Log.d("InAppReview", "Rating complete")
}
}
Note: Once the flow is finished, this API does not indicate whether the user reviewed the app or not. Thus, no matter the result, you need to continue your app flow as normal. So, do not need to inform the user that the review has been published successfully or not, just continue your app’s normal flow on OnComplete.
Here is the final look at the code:
class MainActivity : AppCompatActivity() {
private lateinit var reviewManager: ReviewManager
private lateinit var reviewInfo: ReviewInfo
private lateinit var binding: ActivityMainBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
initReviewInfo()
binding.reviewButton.setOnClickListener {
startReviewFlow()
}
}
/**
* Must pre-cache the reviewInfo object for later use to show in-app review dialog.
*/
private fun initReviewInfo() {
reviewManager = ReviewManagerFactory.create(applicationContext)
val manager = reviewManager.requestReviewFlow()
manager.addOnCompleteListener { task: Task<ReviewInfo?> ->
if (task.isSuccessful) {
reviewInfo = task.result
} else {
Log.d("InAppReview", "ReviewFlow failed to start")
}
}
}
private fun startReviewFlow() {
if (::reviewManager.isInitialized) {
val flow = reviewManager.launchReviewFlow(this, reviewInfo)
flow.addOnCompleteListener {
Log.d("InAppReview", "Rating complete")
}
}
}
}
Once it is implemented correctly, Dialog will look like this:
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. For more details have a look into this.
- 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.
Done! Happy Coding
If you have any questions or feedback, please feel free to contact me.
Connect with me on LinkedIn.
Best Regards.
Comments
Post a Comment