如何直接打开谷歌Play商店应用,而无需选配意图 [英] How to open Google play store app directly without chooser intent

查看:534
本文介绍了如何直接打开谷歌Play商店应用,而无需选配意图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想直接从我的应用程序打开谷歌Play商店。

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?

更新:

使用此修正这个问题。

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();
                    }

                }

            }

但现在的问题是,它开启Play商店的主页,但我想它重定向到一个特定的应用程序的软件包名称我发送。任何一个可以帮助我。

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.

帮助总是AP preciated。

Help is always appreciated.

推荐答案

使用code ...它为我的作品

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("http://play.google.com/store/apps/details?id=" + appPackageName)));
     }

这篇关于如何直接打开谷歌Play商店应用,而无需选配意图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆