13

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.

ישו אוהב אותך
  • 26,433
  • 11
  • 70
  • 92
Android
  • 915
  • 4
  • 11
  • 28
  • which extra apps it shows? – Anand Prakash Nov 20 '14 at 05:59
  • check this link, im pretty sure you can set your intent just like this but for Action_View, im not sure though never tried http://stackoverflow.com/questions/26625505/restricting-share-options/26625813#26625813 – JRowan Nov 20 '14 at 06:00
  • pass the google store package name(find somewhere as i dont know) in the intent and it will start the google store – therealprashant Nov 20 '14 at 06:00

2 Answers2

37

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)));
     }
wblaschko
  • 3,222
  • 1
  • 17
  • 23
Prince Thomas
  • 990
  • 7
  • 10
7

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

wblaschko
  • 3,222
  • 1
  • 17
  • 23
VinothKathir
  • 260
  • 2
  • 8