Skip to content

Instantly share code, notes, and snippets.

@ahmed-shehataa
Last active August 9, 2020 17:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahmed-shehataa/a4c72234a0fb164a5183d551111ace61 to your computer and use it in GitHub Desktop.
Save ahmed-shehataa/a4c72234a0fb164a5183d551111ace61 to your computer and use it in GitHub Desktop.
fun Activity.reviewAppDialog() {
val manager = ReviewManagerFactory.create(this)
(manager.requestReviewFlow()).addOnCompleteListener { request ->
if (request.isSuccessful) {
// We got the ReviewInfo object
val reviewInfo = request.result
manager.launchReviewFlow(this, reviewInfo)
} else {
// here ypu can call a normal review (send intent to google play or a browser)
rateApp()
}
}
}
fun Activity.rateApp() {
try {
val sendIntent = Intent().apply {
action = Intent.ACTION_SEND
putExtra(
Intent.ACTION_VIEW,
Uri.parse("market://details?id=$packageName")
)
}
startActivity(sendIntent)
} catch (e: ActivityNotFoundException) {
startActivity(
Intent(
Intent.ACTION_VIEW,
Uri.parse("https://play.google.com/store/apps/details?id=$packageName")
)
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment