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.

3

0

Browse other questions tagged or ask your own question.