How to open Google play store app directly without chooser intent
41,095
Solution 1
use this code...it works for me
final String appPackageName = getPackageName(); // getPackageName() from Context or Activity object
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
}
catch (android.content.ActivityNotFoundException anfe) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)));
}
Solution 2
If i got you correctly, you are looking for this.
final String appPackageName = getPackageName(); // getPackageName() from Context or Activity object
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
} catch (android.content.ActivityNotFoundException anfe) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)));
}
Try this
![Android](https://i.stack.imgur.com/BFvlM.jpg?s=256&g=1)
Author by
Android
Updated on December 25, 2020Comments
-
Android over 3 years
I want to open Google play store directly from my app.
Here is what I am doing now.
try { // Check whether Google Play store is installed or not: this.getPackageManager().getPackageInfo( "com.android.vending", 0); url = "market://details?id=" + packageName; } catch (final Exception e) { url = "https://play.google.com/store/apps/details?id=" + packageName; } // Open the app page in Google Play store: final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); startActivity(intent);
but the problem is that it shows other applications in application chooser box.
I don't want this how can I avoid Chooser box and directly open play store?
Updated :
Fixed this issue by using this:
Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.setData(Uri.parse("market://search?q=foo")); PackageManager pm = getActivity().getPackageManager(); List<ResolveInfo> list = pm.queryIntentActivities(intent, 0); for (int a = 0; a < list.size(); a++) { ResolveInfo info = list.get(a); ActivityInfo activity = info.activityInfo; if (activity.name.contains("com.google.android")) { ComponentName name = new ComponentName( activity.applicationInfo.packageName, activity.name); Intent i = new Intent(Intent.ACTION_MAIN, Uri.parse("http://play.google.com/store/apps/details?id=" + packageName)); i.addCategory(Intent.CATEGORY_LAUNCHER); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); i.setComponent(name); startActivity(i); getActivity().finish(); } } }
but now problem is that it opens the main page of Play store but I want it to redirect to a specific app whose package name I am sending. Can any one help me with this.
Help is always appreciated.
-
IgorGanapolsky almost 9 yearsWhat to do if package is unavailable? It will just display a blank error page...
-
Zohair over 8 yearsPlain and simple example, Cheers mate :)
-
Amar Ilindra about 7 yearschange URL to
https://
-
Amar Ilindra about 7 yearschange URL to
https://
-
Vijay Patole almost 5 yearsThis is not working on Android Pie version.
-
spartygw almost 3 yearsWorks for android 12, so not sure what the deal was 2 years ago with @VijayPatole and Pie.