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

21

298

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://?
Bobbinet answered 30/5, 2012 at 12:54 Comment(4)
This has everything you need: github.com/delight-im/AppRater And you can look up the source code to understand how it's done.Anfractuous
Check out the official way of doing it in 2020Solis
Best way is Google's In-app review now - https://mcmap.net/q/64715/-quot-rate-this-app-quot-link-in-google-play-store-app-on-the-phonePaolapaolina
I have a text message with my apps google play store link. If the app is available in my device, it needs to redirect me to the app. Otherwise needs to open the google play store. Is it possible?Mollymollycoddle
R
597

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();
}
Rowley answered 30/5, 2012 at 13:1 Comment(16)
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? ThanksBobbinet
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.Rowley
Is there any way to do all this but then also actually open the 'Rate This App' dialog. Thanks!Decline
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);Kilovolt
Opens the play store for me, however, the spinner just sits there indefinetly and the page is loading indefinitly. Am I missing something?Doorbell
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.Terrarium
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!Devour
Seems to me like the Intent flags should be Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASKKira
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?Billen
In the catch part, what if there is no intent to handle someurl ? It will crash the App.Bernt
it works fine without any flags, I can return back to my app with back buttonAlpha
@JanMuller seems we don't need those flags anymore (at least starting from 5/6 Android)Alpha
@RuchirBaronia seems you know nothing about uri, intent, protocol, url and so onAlpha
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.Usia
If calling from a non-Activity java class you need to pass the context like context.startActivity(goToMarket);Peterkin
Best way is In-app review now : https://mcmap.net/q/64715/-quot-rate-this-app-quot-link-in-google-play-store-app-on-the-phonePaolapaolina
I
57

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.

Inexperienced answered 22/9, 2015 at 15:14 Comment(1)
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.Usia
M
33

I always use this code:

startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=PackageName")));
Minica answered 26/4, 2015 at 12:53 Comment(10)
Always like one liners.:)Sham
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?Separable
Can You check this ?Minica
@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?Separable
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.whatsappMinica
@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?Separable
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...Minica
@Cabezas. i use this code:` try { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("bazaar://details?id=vow_note.maxsoft.com.vownote")); intent.setData(Uri.parse("myket://comment?id=vow_note.maxsoft.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.}`Separable
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.Usia
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.@UsiaMinica
S
32

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

Solis answered 13/8, 2020 at 22:25 Comment(6)
If you're using Kotlin dependency, you don't need to use this one: implementation 'com.google.android.play:core:1.8.0'Intermit
@Intermit I am glad it worked without the core library, though I didn't receive a thumbs up from you :(Solis
use it careful, In-app review can not always shown because many reasons (eg: old Playstore version, enterprise email, problem with Google Play service) issuetracker.google.com/issues/167352813Chengtu
if you want user to Review app after click on a button, you should not use In-App review too, it may shown only once time a month developer.android.com/guide/playcore/in-app-review#quotasChengtu
@Linh, You can always redirect to playstore in the else condition of above answer as a fallback.Promiscuous
@Promiscuous No, that won't work. Per the comment in the code sample in this answer: "The API does not indicate whether the user reviewed or not, or even whether the review dialog was shown.". Thus, when triggering from a button, you have to always show the store page instead of using this API.Telophase
T
22

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();
        }
    }
}
Tattoo answered 4/8, 2014 at 14:30 Comment(4)
Doesn't answer the question at hand.Mcdonnell
what about code to open the amazon app store listing of your app ?Hexastyle
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.Usia
I have a text message with my apps google play store link. If the app is available in my device, it needs to redirect me to the app. Otherwise needs to open the google play store. Is it possible to redirect me to the app with Google playstore linkMollymollycoddle
L
11

You can always call getInstalledPackages() from the PackageManager class and check to make sure the market class is installed. You could also use queryIntentActivities() to make sure that the Intent you construct will be able to be handled by something, even if it's not the market application. This is probably the best thing to do actually because its the most flexible and robust.

You can check if the market app is there by

Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse("market://search?q=foo"));
PackageManager pm = getPackageManager();
List<ResolveInfo> list = pm.queryIntentActivities(intent, 0);

If the list has at least one entry, the Market's there.

You can use the following to launch Android Market on your application's page, it's a bit more automated:

Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("market://details?id=" + getPackageName()));
startActivity(i);

If you want to test this on your emulator you probably you don't have the market installed on it : see these links for more details:

How To Enable the Android Market in the Google Android Emulator

Installing Google Play on Android Emulator

Liveryman answered 30/5, 2012 at 13:9 Comment(1)
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? ThanksBobbinet
B
8

I use this approach to make user rate my apps:

public static void showRateDialog(final Context context) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context)
            .setTitle("Rate application")
            .setMessage("Please, rate the app at PlayMarket")
            .setPositiveButton("RATE", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    if (context != null) {
                        String link = "market://details?id=";
                        try {
                            // play market available
                            context.getPackageManager()
                                    .getPackageInfo("com.android.vending", 0);
                        // not available
                        } catch (PackageManager.NameNotFoundException e) {
                            e.printStackTrace();
                            // should use browser
                            link = "https://play.google.com/store/apps/details?id=";
                        }
                        // starts external action
                        context.startActivity(new Intent(Intent.ACTION_VIEW, 
                                Uri.parse(link + context.getPackageName())));
                    }
                }
            })
            .setNegativeButton("CANCEL", null);
    builder.show();
}
Bonneau answered 16/7, 2015 at 21:52 Comment(2)
Whats this for? - market://details?id= My app link is like https:\\play.google.com\apps\details?id=Aubry
@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 startBonneau
F
7

A kotlin version

fun openAppInPlayStore() {
    val uri = Uri.parse("market://details?id=" + context.packageName)
    val goToMarketIntent = Intent(Intent.ACTION_VIEW, uri)

    var flags = Intent.FLAG_ACTIVITY_NO_HISTORY or Intent.FLAG_ACTIVITY_MULTIPLE_TASK
    flags = if (Build.VERSION.SDK_INT >= 21) {
        flags or Intent.FLAG_ACTIVITY_NEW_DOCUMENT
    } else {
        flags or Intent.FLAG_ACTIVITY_CLEAR_TASK
    }
    goToMarketIntent.addFlags(flags)

    try {
        startActivity(context, goToMarketIntent, null)
    } catch (e: ActivityNotFoundException) {
        val intent = Intent(Intent.ACTION_VIEW,
                Uri.parse("http://play.google.com/store/apps/details?id=" + context.packageName))

        startActivity(context, intent, null)
    }
}
Ferrari answered 10/2, 2019 at 9:51 Comment(2)
What's difference between the first link Uri.parse("market://details?id=" + context.packageName) and the second one in catch block Uri.parse("http://play.google.com/store/apps/details?id=" + context.packageName)) ? I think it's redundantRebec
The first is a scheme for the play store app. So the app try to open the play store app. If this does not work because of reasons the http link will called. In earlier days, this fallback was even more necessary. I think in 2022 99% should be able to open the Play Store app via Scheme.Ferrari
S
7

Java 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'
}

Add this method to your Activity:

void askRatings() {
    ReviewManager manager = ReviewManagerFactory.create(this);
    Task<ReviewInfo> request = manager.requestReviewFlow();
    request.addOnCompleteListener(task -> {
        if (task.isSuccessful()) {
            // We can get the ReviewInfo object
            ReviewInfo reviewInfo = task.getResult();
            Task<Void> flow = manager.launchReviewFlow(this, reviewInfo);
            flow.addOnCompleteListener(task2 -> {
                // 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.
        }
    });
}

And then you can simply call it using

askRatings();

Source

enter image description here

Solis answered 13/8, 2020 at 22:20 Comment(2)
using implementation ? is that adding another MB of extra library within our project @Solis .... OmgAlurta
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)Solis
P
7

From now you can use In App Rating feature by Google.

Here is Kotlin/Java integration official guide

The Google Play In-App Review API lets you prompt users to submit Play Store ratings and reviews without the inconvenience of leaving your app or game.

Generally, the in-app review flow (see figure 1) can be triggered at any time throughout the user journey of your app. During the flow, the user has the ability to rate your app using the 1 to 5 star system and to add an optional comment. Once submitted, the review is sent to the Play Store and eventually displayed.

sc

Paolapaolina answered 22/1, 2021 at 5:53 Comment(2)
That in-app rating feature is not guaranteed to be shown and can only be displayed once.Anguish
@EzequielAdrian It is for the better, because the last thing the users want to see is being spammed with "Rate Me" prompts.Largish
G
6

Play Store Rating

 btn_rate_us.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Uri uri = Uri.parse("market://details?id=" + getPackageName());
                Intent goToMarket = new 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 |
                        Intent.FLAG_ACTIVITY_NEW_DOCUMENT |
                        Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
                try {
                    startActivity(goToMarket);
                } catch (ActivityNotFoundException e) {
                    startActivity(new Intent(Intent.ACTION_VIEW,
                            Uri.parse("http://play.google.com/store/apps/details?id=" + getPackageName())));
                }
            }
        });
Gooding answered 18/6, 2018 at 11:6 Comment(0)
G
5

A point regarding all the answers that have implementations based on the getPackageName() strategy is that using BuildConfig.APPLICATION_ID may be more straight forward and works well if you use the same code base to build multiple apps with different app ids (for example, a white label product).

Gastrostomy answered 14/5, 2017 at 4:38 Comment(0)
D
4

You can use this, it works for me

public static void showRateDialogForRate(final Context context) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context)
            .setTitle("Rate application")
            .setMessage("Please, rate the app at PlayMarket")
            .setPositiveButton("RATE", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    if (context != null) {
                        ////////////////////////////////
                        Uri uri = Uri.parse("market://details?id=" + context.getPackageName());
                        Intent goToMarket = new 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 |
                                Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET |
                                Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
                        try {
                            context.startActivity(goToMarket);
                        } catch (ActivityNotFoundException e) {
                            context.startActivity(new Intent(Intent.ACTION_VIEW,
                                    Uri.parse("http://play.google.com/store/apps/details?id=" + context.getPackageName())));
                        }


                    }
                }
            })
            .setNegativeButton("CANCEL", null);
    builder.show();
}
Doddered answered 28/4, 2016 at 11:18 Comment(0)
L
4

Declare a method in you activity class. Then copy and paste the code below.

private void OpenAppInPlayStore(){

    Uri uri = Uri.parse("market://details?id=" + this.getPackageName());
    Intent goToMarket = new 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 |
            Intent.FLAG_ACTIVITY_NEW_DOCUMENT |
            Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
    try {
        startActivity(goToMarket);
    } catch (ActivityNotFoundException e) {
        startActivity(new Intent(Intent.ACTION_VIEW,
                Uri.parse("http://play.google.com/store/apps/details?id=" + this.getPackageName())));
    }

}

Now call this method from anywhere of your code.

Follow the image below from my practical project.

enter image description here

Landes answered 10/6, 2020 at 17:7 Comment(0)
M
3

Another approach that may work for you is Linkify. If I have a TextView that is asking the user to rate the app, I can linkify a couple of words in the text so they are highlighted and when the user touches them, the play store opens up, ready for their review:

class playTransformFilter implements TransformFilter {
   public String transformUrl(Matcher match, String url) {
        return "market://details?id=com.qwertyasd.yourapp";
   }
}

class playMatchFilter implements MatchFilter {
    public boolean acceptMatch(CharSequence s, int start, int end) {
        return true;
    }
}
text1 = (TextView) findViewById(R.id.text1);
text1.setText("Please rate it.");
final Pattern playMatcher = Pattern.compile("rate it");
Linkify.addLinks(text1, playMatcher, "", 
                   new playMatchFilter(), new playTransformFilter());
Meissner answered 20/2, 2013 at 3:21 Comment(0)
B
3

I use the following approach by combining this and this answer without using exception based programming and also supports pre-API 21 intent flag.

@SuppressWarnings("deprecation")
private Intent getRateIntent()
{
  String url        = isMarketAppInstalled() ? "market://details" : "https://play.google.com/store/apps/details";
  Intent rateIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(String.format("%s?id=%s", url, getPackageName())));
  int intentFlags   = Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_MULTIPLE_TASK;
  intentFlags      |= Build.VERSION.SDK_INT >= 21 ? Intent.FLAG_ACTIVITY_NEW_DOCUMENT : Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET;
  rateIntent.addFlags(intentFlags);
  return rateIntent;
}

private boolean isMarketAppInstalled()
{
  Intent marketIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://search?q=anyText"));
  return getPackageManager().queryIntentActivities(marketIntent, 0).size() > 0;
}


// use
startActivity(getRateIntent());

Since the intent flag FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET is deprecated from API 21 I use the @SuppressWarnings("deprecation") tag on the getRateIntent method because my app target SDK is below API 21.


I also tried the official Google way suggested on their website (Dec. 6th 2019). To what I see it doesn't handle the case if the Play Store app isn't installed:

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(
    "https://play.google.com/store/apps/details?id=com.example.android"));
intent.setPackage("com.android.vending");
startActivity(intent);
Boisterous answered 6/12, 2019 at 12:31 Comment(0)
G
2

You can use this simple code for rate your app in your activity.

try {
    Uri uri = Uri.parse("market://details?id=" + getPackageName());
    Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
    startActivity(goToMarket);
} catch (ActivityNotFoundException e) {
    startActivity(new Intent(Intent.ACTION_VIEW,
    Uri.parse("http://play.google.com/store/apps/details?id=" + getPackageName())));
}
Gracielagracile answered 5/11, 2015 at 8:34 Comment(2)
Whats this for? - market://details?id= My app link is like https:\\play.google.com\apps\details?id=Aubry
@SagarBalyan If the user has multiple app markets, it will open the default store or show them an intent to every store available.Bjorn
B
2
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.support.annotation.StringRes;
import android.widget.Toast;

public class PlayStoreLink {

public void checkForUpdate(Context context, int applicationId) 
{
    try {
        context.startActivity(new Intent(Intent.ACTION_VIEW,
                Uri.parse(context.getString(R.string.url_market_details)
                        + applicationId)));
    } catch (android.content.ActivityNotFoundException anfe) {
        try {
            context.startActivity(new Intent(Intent.ACTION_VIEW,
                    Uri.parse(context.getString(R.string.url_playstore_app)
                            + applicationId)));
        } catch (Exception e) {
            Toast.makeText(context,
                    R.string.install_google_play_store,
                    Toast.LENGTH_SHORT).show();
        }
    }
}

public void moreApps(Context context, @StringRes int devName) {
    try {
        context.startActivity(new Intent(Intent.ACTION_VIEW,
                Uri.parse(context.getString(R.string.url_market_search_app)
                        + context.getString(devName))));
    } catch (android.content.ActivityNotFoundException anfe) {
        try {
            context.startActivity(new Intent(Intent.ACTION_VIEW,
                    Uri.parse(context.getString(R.string.url_playstore_search_app)
                            + context.getString(devName))));
        } catch (Exception e) {
            Toast.makeText(context,
                    R.string.install_google_play_store,
                    Toast.LENGTH_SHORT).show();
        }
    }
}

public void rateApp(Context context, int applicationId) {
    try {
        Uri uri = Uri.parse(context.getString(R.string.url_market_details)
                + applicationId);
        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
        int flags = Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_MULTIPLE_TASK;
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT_WATCH)
            flags |= Intent.FLAG_ACTIVITY_NEW_DOCUMENT;
        else
            flags |= Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET;
        intent.addFlags(flags);
        context.startActivity(intent);
    } catch (ActivityNotFoundException e) {
        checkForUpdate(context, applicationId);
    }
}
}

<string name="install_google_play_store" translatable="false">Please install google play store and then try again.</string>
<string name="url_market_details" translatable="false">market://details?id=</string>
<string name="url_playstore_app" translatable="false">https://play.google.com/store/apps/details?id=</string>
<string name="url_market_search_app" translatable="false">market://search?q=pub:</string>
<string name="url_playstore_search_app" translatable="false">http://play.google.com/store/search?q=pub:</string>
<string name="app_link" translatable="false">https://play.google.com/store/apps/details?id=</string>

devName is the name of Developer Account on Play Store

Bernt answered 29/9, 2018 at 8:39 Comment(0)
H
2

A lot of time has passed since this answer and now THERE IS A WAY TO ATTACH THE GOOGLE PLAY REVIEW WINDOW TO YOUR APP

https://developer.android.com/guide/playcore/in-app-review

// In your app’s build.gradle file:
...
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.10.0'

    // For Kotlin users also add the Kotlin extensions library for Play Core:
    implementation 'com.google.android.play:core-ktx:1.8.1'
    ...
}

Then whenever you want to show the rate pop-up

final ReviewManager manager = ReviewManagerFactory.create(context);
final Task<ReviewInfo> request = manager.requestReviewFlow();
request.addOnCompleteListener(task -> {
    if (task.isSuccessful()) {
        // We can get the ReviewInfo object
        ReviewInfo reviewInfo = task.getResult();
        Task<Void> flow = manager.launchReviewFlow(context, reviewInfo);
flow.addOnCompleteListener(task -> {
    // 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, log or handle the error code.
        @ReviewErrorCode int reviewErrorCode = ((TaskException) task.getException()).getErrorCode();
    }
});

As said in the comments THE API DOESN'T LET YOU KNOW WHAT RATING THE USER GAVE

Also google has strict guidelines to use this api, the frequency you are allowed to show the window is limited and also you are not allowed to induce the user to give you a good review. you can check the full documentation and guidelines in the link above

Halter answered 23/4, 2021 at 1:43 Comment(0)
O
0

Here is my version using the BuildConfig class:

Intent marketIntent = new Intent(Intent.ACTION_VIEW, uri);

marketIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    marketIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
}

try {
    startActivity(marketIntent);
} catch (ActivityNotFoundException e) {
    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + BuildConfig.APPLICATION_ID)));
}
Orthohydrogen answered 26/9, 2020 at 10:6 Comment(0)
K
0

In-App Review API is a long-awaited feature that Google has launched in August 2020 like Apple did in 2016 for iOS apps.

With this API users will review and rate an application without leaving it. Google suggestion to developers not to force users to rate or review all the time as this API allocate a quota to each user on the specific usage of the application in a time. Surely developers would not be able to interrupt users with an attractive pop-up in the middle of their task.

Java

In Application level (build.gradle)

       dependencies {
            // This dependency from the Google Maven repository.
            // include that repository in your project's build.gradle file.
            implementation 'com.google.android.play:core:1.9.0'
        }

 

boolean isGMSAvailable = false;
int result = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(this);
isGMSAvailable = (com.google.android.gms.common.ConnectionResult.SUCCESS == result);
  if(isGMSAvailable)
  {
    ReviewManager manager = ReviewManagerFactory.create(this);
    Task<ReviewInfo> request = manager.requestReviewFlow();
    request.addOnCompleteListener(task -> {
      try {
        if (task.isSuccessful())
        {
           // getting ReviewInfo object
            ReviewInfo reviewInfo = task.getResult();
            Task<Void> flow = manager.launchReviewFlow(this, reviewInfo);
            flow.addOnCompleteListener(task2 -> {
                // 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
           // call old method for rating and user will land in Play Store App page
           Utils.rateOnPlayStore(this);       
        }
        } catch (Exception ex)
        {
            Log.e("review Ex", "review & rate: "+ ex);
                 }
                });
    }
    else
    {
       // if user has not installed Google play services in his/her device you land them to 
       // specific store e.g. Huawei AppGallery or Samsung Galaxy Store 
       Utils.rateOnOtherStore(this);
    }   

Kotlin

val manager = ReviewManagerFactory.create(context)
val request = manager.requestReviewFlow()
request.addOnCompleteListener { request ->
    if (request.isSuccessful) {
        // We got the ReviewInfo object
        val reviewInfo = request.result
    } else {
        // There was some problem, continue regardless of the result.
    }
}

//Launch the in-app review flow

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.
}

for Testing use FakeReviewManager

//java
ReviewManager manager = new FakeReviewManager(this);

//Kotlin
val manager = FakeReviewManager(context)
Kavita answered 5/1, 2021 at 8:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.