Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open Google play store app directly without chooser intent [duplicate]

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.

like image 403
Android Avatar asked Nov 20 '14 05:11

Android


People also ask

How do I stop my Play Store from redirecting?

From the main device settings, go to Apps, then find Google Play Store in the list, click Open by default, then Open supported links, then Don't open in this app. Older Android: From the main device settings, go to Apps, then find Play Store in the list, and click Clear defaults.


1 Answers

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)));
     }
like image 85
Prince Thomas Avatar answered Oct 13 '22 00:10

Prince Thomas