applibgroup / HarmonyOS-Knowledgebase

This repository contains code samples of HarmonyOS Training
Apache License 2.0
15 stars 6 forks source link

How to implement method to launch App Gallery in HamonyOS application? #50

Closed chiragbhatt3 closed 3 years ago

chiragbhatt3 commented 3 years ago

Query description

I am working on an open-source library for HarmonyOS app development which is used to prompt app users for rating the app on App Gallery. For that, I need to implement a method to launch the app gallery whenever the user agrees to give feedback. For Android, the same functionality is achieved through the following code

public void tryCollectingFeedback(@NonNull final Activity currentActivity, String packageName) {
        String GOOGLE_PLAY_STORE_URI_PREFIX = "https://play.google.com/store/apps/details?id=";
        try {
            Uri uri = Uri.parse(GOOGLE_PLAY_STORE_URI_PREFIX + packageName);
            currentActivity.startActivity(new Intent(ACTION_VIEW, uri));

        } catch (final ActivityNotFoundException ignored) {
        }
    }

What is the alternative for this in HarmonyOS ?

Stackoverflow link:

https://stackoverflow.com/questions/68590480/how-to-implement-method-to-launch-app-gallery-in-hamonyos-application

Additional information

Developer Platform: Windows DevEco Studio version: 2.1.0.303 SDK API version: 5 SDK version: 2.1.1.21 Device: Not required Device OS version: Not required

Regards, Chirag

Meknaj commented 3 years ago

You can use the below snippet to launch the app gallery, packagename refers to the name of the package in appgallery

Intent.OperationBuilder operationBuilder = new Intent.OperationBuilder(); operationBuilder.withBundleName(HUAWEI_APP_GALLERY_URI_PREFIX); operationBuilder.withFlags(Intent.FLAG_ABILITY_NEW_MISSION); operationBuilder.withAction(HUAWEI_APP_GALLERY_ACTION); Operation operation = operationBuilder.build(); Intent intent = new Intent(); intent.setParam("APP_PACKAGENAME", packageName); intent.setOperation(operation); ability.startAbility(intent);