"Rate This App"-link in Google Play store app on the phone

203,646

Solution 1

I open the Play Store from my App with the following code:

            val uri: Uri = Uri.parse("market://details?id=$packageName")
            val goToMarket = 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. 
            goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY or
                    Intent.FLAG_ACTIVITY_NEW_DOCUMENT or
                    Intent.FLAG_ACTIVITY_MULTIPLE_TASK)
            try {
                startActivity(goToMarket)
            } catch (e: ActivityNotFoundException) {
                startActivity(Intent(Intent.ACTION_VIEW,
                        Uri.parse("http://play.google.com/store/apps/details?id=$packageName")))
            }

Option 2: is to use resolveActivity instead of try..catch

if (sendIntent.resolveActivity(getPackageManager()) != null) {
     startActivity(chooser);
} else {
    openUrl();
}

Solution 2

Here is a working and up to date code :)

/*
* Start with rating the app
* Determine if the Play Store is installed on the device
*
* */
public void rateApp()
{
    try
    {
        Intent rateIntent = rateIntentForUrl("market://details");
        startActivity(rateIntent);
    }
    catch (ActivityNotFoundException e)
    {
        Intent rateIntent = rateIntentForUrl("https://play.google.com/store/apps/details");
        startActivity(rateIntent);
    }
}

private Intent rateIntentForUrl(String url)
{
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(String.format("%s?id=%s", url, getPackageName())));
    int flags = Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_MULTIPLE_TASK;
    if (Build.VERSION.SDK_INT >= 21)
    {
        flags |= Intent.FLAG_ACTIVITY_NEW_DOCUMENT;
    }
    else
    {
        //noinspection deprecation
        flags |= Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET;
    }
    intent.addFlags(flags);
    return intent;
}

Put the code in the Activity you would like to call it from.
When the user clicks a button to rate the app, just call the rateApp() function.

Solution 3

I always use this code:

startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=PackageName")));

Solution 4

Kotlin solution (In-app review API by Google in 2020):

You can now use In app review API provided by Google out of the box.

First, in your build.gradle(app) file, add following dependencies (full setup can be found here)

dependencies {
    // This dependency is downloaded from the Google’s Maven repository.
    // So, make sure you also include that repository in your project's build.gradle file.
    implementation 'com.google.android.play:core:1.8.0'
    implementation 'com.google.android.play:core-ktx:1.8.1'
}

Create a method and put this code inside:

val manager = ReviewManagerFactory.create(context)
val request = manager.requestReviewFlow()
request.addOnCompleteListener { request ->
    if (request.isSuccessful) {
        // We got the ReviewInfo object
        val reviewInfo = request.result
        val flow = manager.launchReviewFlow(activity, reviewInfo)
        flow.addOnCompleteListener { _ ->
          // The flow has finished. The API does not indicate whether the user
          // reviewed or not, or even whether the review dialog was shown. Thus, no
         // matter the result, we continue our app flow.
        }
    } else {
        // There was some problem, continue regardless of the result.
    }
}

Source

enter image description here

Solution 5

This is if you publish your app in both Google Play Store and Amazon Appstore. I also handle the case that users (especially in China) don't have both app store and browser.

public void goToMyApp(boolean googlePlay) {//true if Google Play, false if Amazone Store
    try {
       startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse((googlePlay ? "market://details?id=" : "amzn://apps/android?p=") +getPackageName())));
    } catch (ActivityNotFoundException e1) {
        try {
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse((googlePlay ? "http://play.google.com/store/apps/details?id=" : "http://www.amazon.com/gp/mas/dl/android?p=") +getPackageName())));
        } catch (ActivityNotFoundException e2) {
            Toast.makeText(this, "You don't have any app that can open this link", Toast.LENGTH_SHORT).show();
        }
    }
}
Share:
203,646

Related videos on Youtube

Adreno
Author by

Adreno

Updated on July 08, 2022

Comments

  • Adreno
    Adreno almost 2 years

    I'd like to put a "Rate This App"-link in an Android App to open up the app-listing in the user's Google Play store app on their phone.

    1. What code do I have to write to create the market:// or http://-link open in the Google Play store app on the phone?
    2. Where do you put the code?
    3. Does anyone have a sample implementation of this?
    4. Do you have to specify the screen where the market:// or http:// link will be placed, and which is the best to use - market:// or http://?
  • Adreno
    Adreno about 12 years
    Where in the androidmanifest.xml do I place this code? Do I need to add anything else? How does that correspond to an actual link or button on a screen that the user presses? Thanks
  • Adreno
    Adreno about 12 years
    Where in the androidmanifest.xml do I place this code? Do I need to add anything else? How does that correspond to an actual link or button on a screen that the user presses? Thanks
  • MRD
    MRD about 12 years
    You don't need to add any code to the manifest. You just have to place this code within the OnClickListener of your button/link, so when the button is clicked, the code is executed and the Play Store is launched.
  • edwoollard
    edwoollard almost 12 years
    Is there any way to do all this but then also actually open the 'Rate This App' dialog. Thanks!
  • Jan Muller
    Jan Muller over 10 years
    This solution does not count with Play market backstack. After pressing back button, you are not taken back to your application. If you want it, add this line: intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
  • Alan Ford
    Alan Ford over 9 years
    Opens the play store for me, however, the spinner just sits there indefinetly and the page is loading indefinitly. Am I missing something?
  • Admin
    Admin over 9 years
    Doesn't answer the question at hand.
  • xnagyg
    xnagyg almost 9 years
    Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET: This constant was deprecated in API level 21. As of API 21 this performs identically to FLAG_ACTIVITY_NEW_DOCUMENT which should be used instead of this.
  • Buddy
    Buddy almost 9 years
    I don't think that this solution is the proper way to rate the app. You have to take the user directly to the rating section. In this solution, user has to scroll down to rate section which is tiresome and might stimulate user to exit without rating. The latter happens a lot in my case!
  • androidStud
    androidStud almost 8 years
    Always like one liners.:)
  • Mina Dahesh
    Mina Dahesh over 7 years
    i use it but it shows this error- ` android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=market://details?id=PackageName }`- what can i do?
  • Cabezas
    Cabezas over 7 years
    Can You check this ?
  • Mina Dahesh
    Mina Dahesh over 7 years
    @Cabezas. generaly i want to show all existed market on phone. with clicking on which of them,if my app existed,market shows the app. So waht should i do?
  • Cabezas
    Cabezas over 7 years
    for example whatsapp is play.google.com/store/apps/details?id=com.whatsapp, you should go to googleplay and you can see your id.. id=com.whatsapp
  • Mina Dahesh
    Mina Dahesh over 7 years
    @Cabezas. if i want to use more than 1 market,what should i do?can i use intent.setData... more than one time?and how can i sure about its corrected before i upload/publish my app?
  • Cabezas
    Cabezas over 7 years
    I use this line for google play, I don't know if I can use for others market with this line. You can put a webView, for others... It's better if you publish the app, then in your second version, you can add the rate. Because you know the id...
  • Mina Dahesh
    Mina Dahesh over 7 years
    @Cabezas. i use this code:` try { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("bazaar://details?id=vow_note.maxso‌​ft.com.vownote")); intent.setData(Uri.parse("myket://comment?id=vow_note.maxsof‌​t.com.vownote")); startActivity(intent); }catch (ActivityNotFoundException e1) { try { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("MARKET URL"))); startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("MARKET URL"))); } catch (ActivityNotFoundException e2) {Toast.}`
  • vlazzle
    vlazzle almost 7 years
    Seems to me like the Intent flags should be Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK
  • Sagar Balyan
    Sagar Balyan over 6 years
    Whats this for? - market://details?id= My app link is like https:\\play.google.com\apps\details?id=
  • Sagar Balyan
    Sagar Balyan over 6 years
    Whats this for? - market://details?id= My app link is like https:\\play.google.com\apps\details?id=
  • gtgray
    gtgray over 6 years
    @SagarBalyan, It is a special uri for opening your app page at google play market application. If you start activity with link you provided android will open your app page in default browser or will give you a choice what browser app to start
  • Mathi Arasan
    Mathi Arasan about 6 years
    How do I know user rated or not. Becuase, I don't want to promote an alert to review. So, How can I cross check to stop promoting to request review?
  • Pratik Saluja
    Pratik Saluja almost 6 years
    In the catch part, what if there is no intent to handle someurl ? It will crash the App.
  • isJulian00
    isJulian00 over 5 years
    what about code to open the amazon app store listing of your app ?
  • user25
    user25 over 5 years
    it works fine without any flags, I can return back to my app with back button
  • user25
    user25 over 5 years
    @JanMuller seems we don't need those flags anymore (at least starting from 5/6 Android)
  • user25
    user25 over 5 years
    @RuchirBaronia seems you know nothing about uri, intent, protocol, url and so on
  • A P
    A P over 4 years
    @SagarBalyan If the user has multiple app markets, it will open the default store or show them an intent to every store available.
  • s3c
    s3c over 4 years
    What NuGet Package should I add, and what namespace should I be using for Intent to be a viable type? I found Android.Content, but I am at loss with Intent in Xamarin Forms.
  • s3c
    s3c over 4 years
    What NuGet Package should I add, and what namespace should I be using for Intent to be a viable type? I found Android.Content, but I am at loss with Intent in Xamarin Forms.
  • s3c
    s3c over 4 years
    What NuGet Package should I add, and what namespace should I be using for Intent to be a viable type? I found Android.Content, but I am at loss with Intent in Xamarin Forms.
  • s3c
    s3c over 4 years
    What NuGet Package should I add, and what namespace should I be using for Intent to be a viable type? I found Android.Content, but I am at loss with Intent in Xamarin Forms.
  • Cabezas
    Cabezas over 4 years
    Whatsapp's packageName is com.whatsapp, you can check in this linkWhen you create an app in Android studio you should be to put packageName.@s3c
  • DMur
    DMur over 4 years
    If calling from a non-Activity java class you need to pass the context like context.startActivity(goToMarket);
  • dansamosudov
    dansamosudov almost 4 years
    If you're using Kotlin dependency, you don't need to use this one: implementation 'com.google.android.play:core:1.8.0'
  • iDecode
    iDecode almost 4 years
    @dansamosudov I am glad it worked without the core library, though I didn't receive a thumbs up from you :(
  • Khemraj Sharma
    Khemraj Sharma over 3 years
    Best way is In-app review now : stackoverflow.com/a/65839978/6891563
  • gumuruh
    gumuruh about 2 years
    using implementation ? is that adding another MB of extra library within our project @iDecode .... Omg
  • iDecode
    iDecode about 2 years
    It will definitely add to the size of your app but I don't think that will be in MBs. It would be few KBs (although I haven't checked)