How to open the Huawei AppGallery directly?

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

Huawei App Gallery:

  • Scheme: market:// or appmarket://
  • Package: com.huawei.appmarket

vs. Google Play Store:

  • Scheme: market://
  • Package: com.android.vending

Here is a snippet for the Huawei App Gallery:

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

Here is the snippet for 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);
}

Here is the snippet to allow the user to pick Any Available Store on the device:

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

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)