Muhammad Hassaan
Muhammad Hassaan

Reputation: 35

How to send a user to Google play to rate the app?

I am calling this function on a button click to send the user on Google play to rate the app. But it is giving me error "To view this content, install and set up a web browsing app."

private void rateMe() {
        try {
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=$packageName")));
        } catch (ActivityNotFoundException e) {
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=$packageName")));
        }
    }

Upvotes: 0

Views: 179

Answers (1)

yangfengfan
yangfengfan

Reputation: 161

I don’t know if you use Java or Kotlin.

if Java:

 private void rateMe() {
    try {
        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + getPackageName())));
    } catch (ActivityNotFoundException e) {
        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=" + getPackageName())));
    }
}

if Kotlin:

private fun rateMe() {
    try {
        startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=$packageName")))
    } catch (e: ActivityNotFoundException) {
        startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=$packageName")))
    }
}

Upvotes: 0

Related Questions