HarmonyOS鸿蒙Next中APP Linking怎么跳转应用市场详情页

HarmonyOS鸿蒙Next中APP Linking怎么跳转应用市场详情页 用applinking做统一链接跳转,如果安装了应用则拉起应用,未安装则打开 web页,如何实现做到跳转应用商店详情页呢?

3 回复

可以参考

基于context.startAbility方法拉起指定应用,并携带参数。其中type是固定配置值,uri是"store://appgallery.huawei.com/app/detail"拼接上id参数,才能拉起鸿蒙应用市场详情页面。

uri: ‘store://appgallery.huawei.com/app/detail?id=’+appId

具体代码

import { webview } from '@kit.ArkWeb';
import { common, OpenLinkOptions } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

@Entry
@Component
struct Index {
    @State info: string = '-';
    context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext;
    controller = new webview.WebviewController();

    build() {
        Column({ space: 10 }) {
            Web({
                src: $rawfile('index.html'),
                controller: this.controller
            })
            .height(200)
            .zoomAccess(false)
            .onLoadIntercept((event) => {
                const url: string = event.data.getRequestUrl();
                if (url === 'third-party://pages/toThirdApp/appgallery') {
                    const link: string = "store://appgallery.huawei.com/app/detail?id=com.huawei.hmos.wallet";
                    const openLinkOptions: OpenLinkOptions = {
                        appLinkingOnly: false,
                        parameters: {
                            name: 'test'
                        }
                    };
                    this.context.openLink(link, openLinkOptions).then(() => {
                        this.info = link + ', return message: link success.';
                    }).catch((err: BusinessError) => {
                        console.error(`open link failed. Code is ${err.code}, message is ${err.message}`);
                    });
                }
                // 返回true表示阻止此次加载,否则允许此次加载
                return false;
            });

            Text(`目标应用URL: ${this.info}`)
                .fontSize(15)
                .width('90%');
        }
        .height('100%')
        .width('100%');
    }
}

可以参考https://developer.huawei.com/consumer/cn/doc/harmonyos-faqs-V5/faqs-ability-59-V5

您可以通过隐式指定want参数中的action为ohos.want.action.appdetail并配置uri为store://appgallery.huawei.com来单独拉起应用市场应用

更多关于HarmonyOS鸿蒙Next中APP Linking怎么跳转应用市场详情页的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


在HarmonyOS鸿蒙Next中,通过APP Linking跳转应用市场详情页可以使用ohos.app.ability.Wantohos.app.ability.AbilitystartAbility方法。具体步骤如下:

  1. 创建Want对象,设置action"ohos.settings.app.MANAGE_APPLICATIONS"
  2. Want对象中添加参数bundleName,值为目标应用的包名。
  3. 调用startAbility方法启动应用市场详情页。

代码示例如下:

import Ability from '@ohos.app.ability.Ability';
import Want from '@ohos.app.ability.Want';

let want: Want = {
    action: 'ohos.settings.app.MANAGE_APPLICATIONS',
    parameters: {
        'bundleName': 'com.example.targetapp'
    }
};

let context: Ability = ...; // 获取当前Ability的上下文
context.startAbility(want).then(() => {
    console.log('Jump to app market detail page successfully.');
}).catch((err) => {
    console.error('Failed to jump to app market detail page. Error: ' + JSON.stringify(err));
});

该方法通过Want对象指定跳转行为,并传递目标应用的包名,实现从当前应用跳转到应用市场详情页。

在HarmonyOS鸿蒙Next中,通过APP Linking跳转应用市场详情页,可以使用ohos.app.ability.uriPermissionManager模块中的openAppMarket方法。首先,确保已导入相关模块,然后调用openAppMarket方法并传入应用包名,即可实现跳转。示例代码如下:

import uriPermissionManager from '@ohos.app.ability.uriPermissionManager';

let packageName = 'com.example.app'; // 替换为目标应用的包名
uriPermissionManager.openAppMarket(packageName)
  .then(() => {
    console.log('成功跳转应用市场');
  })
  .catch((err) => {
    console.error('跳转失败:', err);
  });

此代码将跳转到指定应用的应用市场详情页。

回到顶部