Android Intent To Rate App For Play Store

April 18, 2018
val uri = Uri.parse("market://details?id=" + BuildConfig.APPLICATION_ID)
var intent = Intent(Intent.ACTION_VIEW, uri)
// To count with Play market backstack, After pressing back button,
// to taken back to our application, we need to add following flags to intent.
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY or
        Intent.FLAG_ACTIVITY_NEW_DOCUMENT or
        Intent.FLAG_ACTIVITY_MULTIPLE_TASK)

if (intent.resolveActivity(activity.packageManager) != null) {
    startActivity(intent)
}
else {
    intent = Intent(Intent.ACTION_VIEW,
            Uri.parse("http://play.google.com/store/apps/details?id=" + BuildConfig.APPLICATION_ID))
    if (intent.resolveActivity(activity.packageManager) != null) {
        startActivity(intent)
    }
    else {
        Toast.makeText(activity, "No play store or browser app", Toast.LENGTH_LONG).show()
    }
}
This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.