如何直接打开Huawei AppGallery? [英] How to open the Huawei AppGallery directly?

查看:732
本文介绍了如何直接打开Huawei AppGallery?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这是可能的在包中打开我的应用程序(基于包名称),但是在华为AppGallery中该怎么做?

I know that is possible to open my app (based on package name) in Google Play Store, but how to do same in Huawei AppGallery?

推荐答案

在Huawei App Gallery中打开您的应用程序类似于打开Goog​​le Play商店:

Opening your app in the Huawei App Gallery is similar to opening Google Play Store:

华为App Gallery 使用其自己的方案appmarket://:

  • 方案: appmarket://
  • 包装: com.huawei.appmarket
  • Scheme: appmarket://
  • Package: com.huawei.appmarket

vs. Google Play商店:

  • 方案: market://
  • 包装: com.android.vending
  • Scheme: market://
  • Package: com.android.vending

以下是华为应用程序库的摘录:

private void startHuaweiAppGallery() {
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("appmarket://details?id=" + getPackageName()));
    List<ResolveInfo> otherApps = getPackageManager().queryIntentActivities(intent, 0);

    boolean agFound = false;

    for (ResolveInfo app : otherApps) {
        if (app.activityInfo.applicationInfo.packageName.equals("com.huawei.appmarket")) {
            ComponentName psComponent = new ComponentName(app.activityInfo.applicationInfo.packageName, app.activityInfo.name);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_CLEAR_TOP);
            intent.setComponent(psComponent);
            startActivity(intent);

            agFound = true;
            break;
        }
    }

    //Optional, Or copy the Google Play Store URL here (See below)
    if (!agFound) {
        //Your Huawei app ID can be found in the Huawei developer console
        final string HUAWEI_APP_ID = "100864605";

        //ex. https://appgallery.cloud.huawei.com/marketshare/app/C100864605
        intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://appgallery.cloud.huawei.com/marketshare/app/C" + HUAWEI_APP_ID));
        startActivity(intent);
    }
}

以下是 Google Play的代码段:

private void startGooglePlay() {
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + getPackageName()));
    List<ResolveInfo> otherApps = getPackageManager().queryIntentActivities(intent, 0);

    boolean psFound = false;

    for (ResolveInfo app : otherApps) {
        if (app.activityInfo.applicationInfo.packageName.equals("com.android.vending")) {
            ComponentName psComponent = new ComponentName(app.activityInfo.applicationInfo.packageName, app.activityInfo.name);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_CLEAR_TOP);
            intent.setComponent(psComponent);
            startActivity(intent);

            psFound = true;
            break;
        }
    }
    if (!psFound) {
        intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + getPackageName()));
        startActivity(intent);
    }
}

这篇关于如何直接打开Huawei AppGallery?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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