Last active
August 9, 2020 17:34
-
-
Save ahmed-shehataa/a4c72234a0fb164a5183d551111ace61 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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