"Rate This App"-link in Google Play store app on the phone
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.
}
}
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();
}
}
}
Related videos on Youtube
Adreno
Updated on July 08, 2022Comments
-
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.
- What code do I have to write to create the
market://
orhttp://
-link open in the Google Play store app on the phone? - Where do you put the code?
- Does anyone have a sample implementation of this?
- Do you have to specify the screen where the
market://
orhttp://
link will be placed, and which is the best to use -market://
orhttp://
?
-
caw over 8 yearsThis has everything you need: github.com/delight-im/AppRater And you can look up the source code to understand how it's done.
-
iDecode almost 4 yearsCheck out the official way of doing it in 2020
-
Khemraj Sharma over 3 yearsBest way is Google's In-app review now - stackoverflow.com/a/65839978/6891563
- What code do I have to write to create the
-
Adreno about 12 yearsWhere 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 about 12 yearsWhere 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 about 12 yearsYou 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 almost 12 yearsIs there any way to do all this but then also actually open the 'Rate This App' dialog. Thanks!
-
Jan Muller over 10 yearsThis 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 over 9 yearsOpens the play store for me, however, the spinner just sits there indefinetly and the page is loading indefinitly. Am I missing something?
-
Admin over 9 yearsDoesn't answer the question at hand.
-
xnagyg almost 9 yearsIntent.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 almost 9 yearsI 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 almost 8 yearsAlways like one liners.:)
-
Mina Dahesh over 7 yearsi 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 over 7 yearsCan You check this ?
-
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 over 7 yearsfor 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 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 over 7 yearsI 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 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.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.}`
-
vlazzle almost 7 yearsSeems to me like the Intent flags should be
Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK
-
Sagar Balyan over 6 yearsWhats this for? -
market://details?id=
My app link is likehttps:\\play.google.com\apps\details?id=
-
Sagar Balyan over 6 yearsWhats this for? -
market://details?id=
My app link is likehttps:\\play.google.com\apps\details?id=
-
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 about 6 yearsHow 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 almost 6 yearsIn the catch part, what if there is no intent to handle someurl ? It will crash the App.
-
isJulian00 over 5 yearswhat about code to open the amazon app store listing of your app ?
-
user25 over 5 yearsit works fine without any flags, I can return back to my app with back button
-
user25 over 5 years@JanMuller seems we don't need those flags anymore (at least starting from 5/6 Android)
-
user25 over 5 years@RuchirBaronia seems you know nothing about uri, intent, protocol, url and so on
-
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 over 4 yearsWhat NuGet Package should I add, and what namespace should I be
using
forIntent
to be a viable type? I found Android.Content, but I am at loss withIntent
in Xamarin Forms. -
s3c over 4 yearsWhat NuGet Package should I add, and what namespace should I be
using
forIntent
to be a viable type? I found Android.Content, but I am at loss withIntent
in Xamarin Forms. -
s3c over 4 yearsWhat NuGet Package should I add, and what namespace should I be
using
forIntent
to be a viable type? I found Android.Content, but I am at loss withIntent
in Xamarin Forms. -
s3c over 4 yearsWhat NuGet Package should I add, and what namespace should I be
using
forIntent
to be a viable type? I found Android.Content, but I am at loss withIntent
in Xamarin Forms. -
Cabezas over 4 yearsWhatsapp'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 over 4 yearsIf calling from a non-Activity java class you need to pass the context like context.startActivity(goToMarket);
-
dansamosudov almost 4 yearsIf you're using Kotlin dependency, you don't need to use this one:
implementation 'com.google.android.play:core:1.8.0'
-
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 over 3 yearsBest way is In-app review now : stackoverflow.com/a/65839978/6891563
-
gumuruh about 2 yearsusing implementation ? is that adding another MB of extra library within our project @iDecode .... Omg
-
iDecode about 2 yearsIt 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)