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

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打开应用程序。


当前回答

这里的许多答案都建议使用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。

其他回答

进入Android开发者官方链接作为教程,一步一步地从play store中查看并获得应用程序包的代码,如果存在或play store应用程序不存在,然后从web浏览器中打开应用程序。

Android开发者官方链接

https://developer.android.com/distribute/tools/promote/linking.html

链接到应用程序页面

从一个网站:https://play.google.com/store/apps/details?id=<package_name>

从Android应用程序:market://details?id = < package_name >

链接到产品列表

从一个网站:https://play.google.com/store/search?q=pub:<publisher_name>

从Android应用程序:market://search?q =酒吧:< publisher_name >

链接到搜索结果

从网站:https://play.google.com/store/search?q=<search_query>&c=apps

从Android应用程序:market://search?q = < seach_query >和c =应用

科特林:

扩展:

fun Activity.openAppInGooglePlay(){

val appId = BuildConfig.APPLICATION_ID
try {
    this.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=$appId")))
} catch (anfe: ActivityNotFoundException) {
    this.startActivity(
        Intent(
            Intent.ACTION_VIEW,
            Uri.parse("https://play.google.com/store/apps/details?id=$appId")
        )
    )
}}

方法:

    fun openAppInGooglePlay(activity:Activity){

        val appId = BuildConfig.APPLICATION_ID
        try {
            activity.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=$appId")))
        } catch (anfe: ActivityNotFoundException) {
            activity.startActivity(
                Intent(
                    Intent.ACTION_VIEW,
                    Uri.parse("https://play.google.com/store/apps/details?id=$appId")
                )
            )
        }
    }

对于费率应用:重定向到播放商店。 在Flutter中,你可以通过这样的平台通道进行操作

颤振部分:

 static const platform = const MethodChannel('rateApp');   // initialize 

onTap:平台。invokeMethod('urls', {'android_id': 'com.xyz'}),

现在Android原生部分(Java):

private static final String RATEAPP = "rateApp";  // initialize variable

//现在在ConfigureFlutterEngine函数中:

        new MethodChannel(flutterEngine.getDartExecutor().getBinaryMessenger(), RATEAPP)
            .setMethodCallHandler(
                    (call, result) -> {               
                        if (call.method.equals("urls") && call.hasArgument("android_id")) {
                            String id = call.argument("android_id").toString();
                          
                            try {
                                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("$uri" + id)));
                            } catch (android.content.ActivityNotFoundException anfe) {
                                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + id)));
                            }
                            result.success("Done");
                        } else {
                            result.notImplemented();
                        }
                    }
            );

你可以:

final Uri marketUri = Uri.parse("market://details?id=" + packageName);
startActivity(new Intent(Intent.ACTION_VIEW, marketUri));

在这里获取参考资料:

你也可以尝试这个问题公认答案中描述的方法: 无法确定谷歌播放商店是否安装在Android设备上

试试这个

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("market://details?id=com.example.android"));
startActivity(intent);