我已经打开谷歌播放商店使用以下代码

Intent i = new Intent(android.content.Intent.ACTION_VIEW);
i.setData(Uri.parse("https://play.google.com/store/apps/details?id=my packagename "));
startActivity(i);.

但它向我显示了一个完整的操作视图,以选择选项(浏览器/播放商店)。我需要直接在Play Store打开应用程序。


当前回答

以下是上述答案的最终代码,第一次尝试使用谷歌播放商店应用程序打开应用程序,特别是播放商店,如果失败,它将使用web版本启动操作视图: 感谢@Eric, @Jonathan Caballero

public void goToPlayStore() {
        String playStoreMarketUrl = "market://details?id=";
        String playStoreWebUrl = "https://play.google.com/store/apps/details?id=";
        String packageName = getActivity().getPackageName();
        try {
            Intent intent =  getActivity()
                            .getPackageManager()
                            .getLaunchIntentForPackage("com.android.vending");
            if (intent != null) {
                ComponentName androidComponent = new ComponentName("com.android.vending",
                        "com.google.android.finsky.activities.LaunchUrlHandlerActivity");
                intent.setComponent(androidComponent);
                intent.setData(Uri.parse(playStoreMarketUrl + packageName));
            } else {
                intent = new Intent(Intent.ACTION_VIEW, Uri.parse(playStoreMarketUrl + packageName));
            }
            startActivity(intent);
        } catch (ActivityNotFoundException e) {
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(playStoreWebUrl + packageName));
            startActivity(intent);
        }
    }

其他回答

芬兰湾的科特林: 在上下文中创建扩展。

fun Context.openPlayStoreApp(pkgName:String?){
    if(!pkgName.isNullOrEmpty()) {
        try {
            startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=$pkgName")))
        } catch (e: ActivityNotFoundException) {
            startActivity(
                Intent(
                    Intent.ACTION_VIEW,
                    Uri.parse("https://play.google.com/store/apps/details?id=$pkgName")
                )
            )
        }
    }
}

希望它能起作用。

这里的许多答案都建议使用Uri.parse("market://details? "id=" + appPackageName))来打开谷歌Play,但我认为它实际上是不够的:

一些第三方应用程序可以使用定义了“market://”方案的自己的意图过滤器,因此他们可以处理提供的Uri而不是谷歌Play(我在例如snappea应用程序中经历过这种情况)。问题是“如何打开谷歌Play Store?”,所以我假设,你不想打开任何其他应用程序。请注意,例如,应用评级只与GP Store应用相关……

要打开谷歌Play并且只打开谷歌Play,我使用以下方法:

public static void openAppRating(Context context) {
    // you can also use BuildConfig.APPLICATION_ID
    String appId = context.getPackageName();
    Intent rateIntent = new Intent(Intent.ACTION_VIEW,
        Uri.parse("market://details?id=" + appId));
    boolean marketFound = false;

    // find all applications able to handle our rateIntent
    final List<ResolveInfo> otherApps = context.getPackageManager()
        .queryIntentActivities(rateIntent, 0);
    for (ResolveInfo otherApp: otherApps) {
        // look for Google Play application
        if (otherApp.activityInfo.applicationInfo.packageName
                .equals("com.android.vending")) {

            ActivityInfo otherAppActivity = otherApp.activityInfo;
            ComponentName componentName = new ComponentName(
                    otherAppActivity.applicationInfo.packageName,
                    otherAppActivity.name
                    );
            // make sure it does NOT open in the stack of your activity
            rateIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            // task reparenting if needed
            rateIntent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
            // if the Google Play was already open in a search result
            //  this make sure it still go to the app page you requested
            rateIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            // this make sure only the Google Play app is allowed to
            // intercept the intent
            rateIntent.setComponent(componentName);
            context.startActivity(rateIntent);
            marketFound = true;
            break;

        }
    }

    // if GP not present on device, open web browser
    if (!marketFound) {
        Intent webIntent = new Intent(Intent.ACTION_VIEW,
            Uri.parse("https://play.google.com/store/apps/details?id="+appId));
        context.startActivity(webIntent);
    }
}

重点是,当谷歌Play旁边有更多的应用程序可以打开我们的意图时,应用程序选择对话框被跳过,GP应用程序直接启动。

更新: 有时它似乎只打开GP应用程序,而不打开应用程序的配置文件。正如TrevorWiley在他的评论中所说,意图。FLAG_ACTIVITY_CLEAR_TOP可以解决这个问题。(我自己还没有测试…)

请看下面的答案来理解什么是Intent。FLAG_ACTIVITY_RESET_TASK_IF_NEEDED。

这个问题的一些答案已经过时了。

对我来说(在2020年)有效的方法是明确地告诉玩家跳过选择器并直接打开游戏商店应用,如下所示:

“如果你想从Android应用程序链接到你的产品,创建一个 打开URL的意图。当你配置这个意图时,通过 “com.android。自动售货”到Intent.setPackage()中,以便用户看到您的 应用程序的详细信息在谷歌Play Store应用程序,而不是一个选择器。”

这是我用来指导用户在谷歌Play中查看包含包名称com.google.android.apps.maps的应用程序的Kotlin代码:

val intent = Intent(Intent.ACTION_VIEW).apply {
               data = Uri.parse("http://play.google.com/store/apps/details?id=com.google.android.apps.maps")
               setPackage("com.android.vending")
            }
            startActivity(intent)

我希望这能帮助到一些人!

如果你想单独打开谷歌Play(或任何其他应用程序),以上所有答案都可以在同一个应用程序的新视图中打开谷歌Play:

Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.android.vending");

// package name and activity
ComponentName comp = new ComponentName("com.android.vending",
                                       "com.google.android.finsky.activities.LaunchUrlHandlerActivity"); 
launchIntent.setComponent(comp);

// sample to open facebook app
launchIntent.setData(Uri.parse("market://details?id=com.facebook.katana"));
startActivity(launchIntent);

重要的部分是实际上打开谷歌播放或任何其他应用程序独立。

我看到的大多数答案都使用了其他答案的方法,这不是我需要的,希望这能帮助到别人。

的问候。

public void launchPlayStore(Context context, String packageName) {
    Intent intent = null;
    try {
            intent = new Intent(Intent.ACTION_VIEW);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.setData(Uri.parse("market://details?id=" + packageName));
            context.startActivity(intent);
        } catch (android.content.ActivityNotFoundException anfe) {
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + packageName)));
        }
    }