如何直接打开华为应用商店?

35

我认为你做不到。 - Radesh
你想从哪里打开什么并不清楚。是从相册打开你的应用程序,还是从你的应用程序打开相册? - Vladyslav Matviienko
@VladyslavMatviienko 在华为应用商店中打开我的应用。 - Michalsx
你需要修改 华为应用商店 的代码才能打开你的应用程序。这是唯一的方法。 - Vladyslav Matviienko
请参考以下链接中的答案:https://dev59.com/W7noa4cB1Zd3GeqPTZdc#73612735 - MBH
11个回答

47

在华为应用商店中打开您的应用程序类似于打开Google Play Store:

华为应用商店

  • 方案: market://appmarket://
  • 包名: com.huawei.appmarket

Google Play Store:

  • 方案: market://
  • 包名: com.android.vending

这是针对华为应用商店的代码片段:

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

    for (ResolveInfo app : otherApps) {
        String packageName = app.activityInfo.applicationInfo.packageName;
        if (!packageName.equals("com.huawei.appmarket")) {
            continue;
        }

        intent.addFlags(
            Intent.FLAG_ACTIVITY_NEW_TASK | 
            Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | 
            Intent.FLAG_ACTIVITY_CLEAR_TOP
        );
        intent.setComponent(new ComponentName(packageName, app.activityInfo.name));
        startActivity(intent);
        return;
    }

    //Huawei App Gallery N/A. Open app link in browser.
    //Huawei App ID can be found in the Huawei developer console
    final string huaweiAppID = "100864605";

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

以下是Google Play的代码片段:

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

    for (ResolveInfo app : otherApps) {
        String packageName = app.activityInfo.applicationInfo.packageName;
        if (!packageName.equals("com.android.vending")) {
            continue;
        }

        intent.addFlags(
            Intent.FLAG_ACTIVITY_NEW_TASK | 
            Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | 
            Intent.FLAG_ACTIVITY_CLEAR_TOP
        );
        intent.setComponent(new ComponentName(packageName, app.activityInfo.name));
        startActivity(intent);
        return;
    }

    //Google Play N/A. Open app link in browser.
    Uri appUri = Uri.parse(
        "https://play.google.com/store/apps/details?id=" + getPackageName()
    );
    intent = new Intent(Intent.ACTION_VIEW, appUri);
    startActivity(intent);
}

这里是代码片段,允许用户在设备上选择任何可用店铺

private void startAnyStore() {
    Uri detailsUri = Uri.parse("market://details?id=" + getPackageName());
    Intent intent = new Intent(Intent.ACTION_VIEW, detailsUri);
    intent.addFlags(
        Intent.FLAG_ACTIVITY_NEW_TASK | 
        Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | 
        Intent.FLAG_ACTIVITY_CLEAR_TOP
    );
    startActivity(intent);
}

8

1
注意在 HUAWEI_APP_ID 前面的那个 C - Milore
C是什么?它是用于中国大陆分发还是其他什么? - Csaba Toth

7
如果您的应用程序已经在华为应用商店上发布,那么您可以使用此URL直接打开应用程序。
1.带有您的应用程序ID的URL,例如AppGallery的应用程序ID是27162,则可以使用此URL打开它。

https://appgallery.huawei.com/#/app/C27162

您可以将appid替换为您自己的appid。

  1. 使用您应用程序的包名生成URL,例如AppGallery的包名是com.huawei.appmarket,则可以使用此URL打开它。

https://appgallery.cloud.huawei.com/appDetail?pkgName=com.huawei.appmarket

你可以将包名替换为自己的包名。
希望这能有所帮助。

4

华为应用商城现在似乎可以使用与Google Play相同的URI打开详细页面:market://details?id=<applicationId>

我刚刚在AppGallery v11.1.2.304 上尝试了一个在两个商城中都存在的applicationId: adb shell am start -a "android.intent.action.VIEW" -d "market://details?id=busu.blackscreenbatterysaver"


1
这个方案是可行的,但是在我的设备上也安装了第三方市场APKPure。使用这个解决方案将会显示一个对话框来决定使用哪个应用商店来处理意图。此外,一些华为设备仍然安装了Google Play商店和华为应用商店,这也可能触发此对话框。在我们的使用情况下,这不是期望的行为。 - lilienberg
那么你想要的行为是什么? - Adi B
在我们的情况下,我们希望华为应用商店自动打开,而不需要询问用户他喜欢的商店应用程序。常见的用例是要求应用程序评分/反馈、应用程序更新或下载另一个应用程序。在所有情况下,我们都不希望用户选择APKPure。 直接链接到另一个应用程序通常通过应用程序链接而不是普通的深度链接来完成。scheme market://似乎只是作为普通深度链接工作。 - lilienberg
1
如果您希望完全跳过歧义对话框,唯一的方法是使用具有 appmarket:// 模式的深度链接,就像Pierre在接受的答案中所指示的那样。对我来说,AppGallery的https链接并没有像应用链接一样运行,我仍然会得到歧义对话框(选择华为浏览器处理意图的应用程序列表后,它最终将启动设备上的AppGallery本机应用程序,并显示您的应用程序详细信息)- 尝试 adb shell am start -a“android.intent.action.VIEW”-d“https://appgallery.huawei.com/#/app/C103639735” - Adi B
我提到了使用 market:// 模式的通用解决方案(而不是每个商店都有不同的深度链接),因为当你编写一个希望跨平台的应用程序时,这更加方便。 - Adi B

2
在华为应用商店中打开应用的简单方法:
public void reviewApp(String packageName){
        try {
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("appmarket://details?id=" + packageName));
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
        } catch (ActivityNotFoundException anfe) {
            Toast.makeText(this, "Huawei AppGallery not found!", Toast.LENGTH_SHORT).show();
        }
}

然后从您的活动中调用它:

reviewApp(this.getPackageName());

或者:

reviewApp("com.myapp.android");

2
您可以使用华为应用商店提供的徽章服务来推广您的应用程序,包括准备制作徽章的材料、配置应用链接和获取引荐统计数据。通过该服务,您可以高效地收集AppGallery中应用下载的统计信息,并为用户提供静默安装服务,以提高推广效果。
当用户在渠道中点击您的徽章时,用户将被重定向到应用商店上的您的应用详情页面。用户可以点击“安装”按钮自动下载和安装您的应用程序。
  • 制作徽章
  1. 登录AppGallery Connect,点击应用内分发
  2. 点击制作徽章选项卡。
  3. 点击添加,可以通过关键字或应用ID搜索并添加一个已发布的应用程序以制作徽章。
  4. 设置徽章类型在哪里显示徽章渠道名称引荐人。 引荐人是可选的,如果需要归因统计,则需要设置参数。
  5. 单击生成徽章以获取徽章及其链接。

请参考下面的屏幕截图: badge service


这个!我有一种感觉,OP想要这个。 - Csaba Toth

1

通过包名启动Play Store/AppGallery。

private boolean openInStore(String uri){
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        try {
            startActivity(Intent.createChooser(intent,getString(R.string.open_with)));
            return true;
        } catch (ActivityNotFoundException anfe) {
            return false;
        }
    }

    private void startOpenInStore() {
        String playStoreScheme = "market://details?id=", huaweiScheme = "appmarket://details?id=";
        if (!openInStore(playStoreScheme+getPackageName())) {
            if (!openInStore(huaweiScheme + getPackageName())) {
                openInStore("https://play.google.com/store/apps/details?id=" + getPackageName());
            }
        }
    }

0
关于如何链接到AppGallery上的应用详情页或应用列表页:
• 您提到的链接:here 是指应用详情页。华为支持使用徽章服务在AppGallery上展示应用详情页。换句话说,您可以用华为徽章链接替换谷歌链接。您可以在here获取徽章服务的详细信息。
• 对于在AppGallery上的应用列表,除了一些受邀开发者外,华为尚未向所有开发者开放此功能。
希望这能帮到您,如果有任何问题,请告诉我。

0

我认为最短且最简单的方法是运行这个简单链接:https://appgallery.cloud.huawei.com/ag/n/app/<YOUR_APP_ID>

无需配置任何内容,华为将自动处理其余事项。

如何获取“YOUR_APP_ID”?

  1. 前往华为应用商店
  2. 搜索您的应用程序(例如微信
  3. 复制链接末尾的ID(例如https://appgallery.huawei.com/#/app/C5683
  4. 在本例中,WeChat的APP_ID为C5683
  5. 因此,WeChat的华为应用程序链接为https://appgallery.cloud.huawei.com/ag/n/app/C5683

0

以下是直接启动应用商店的方法:

Intent intent = new Intent(Intent.ACTION_VIEW);
Uri.Builder uriBuilder = Uri.parse("https://appgallery.cloud.huawei.com/ag").buildUpon();
intent.setData(uriBuilder.build());
intent.setPackage("com.huawei.appmarket");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接