HarmonyOS 鸿蒙Next应用设置跳转华为应用市场目标APP下载页
HarmonyOS 鸿蒙Next应用设置跳转华为应用市场目标APP下载页
鸿蒙应用设置跳转华为应用市场目标APP下载页
Deep Linking方式
构造拼接bundleName的Deep Linking链接,其中bundleName为需要打开的应用包名,其格式为:
- store://appgallery.huawei.com/app/detail?id= + bundleName
在应用中调用startAbility方法,拉起应用市场应用详情页:
import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import type { common, Want } from '@kit.AbilityKit';
// 拉起应用市场对应的应用详情页面
function startAppGalleryDetailAbility(context: common.UIAbilityContext, bundleName: string): void {
let want: Want = {
action: 'ohos.want.action.appdetail', //隐式指定action为ohos.want.action.appdetail
uri: 'store://appgallery.huawei.com/app/detail?id=' + bundleName, // bundleName为需要打开应用详情的应用包名
};
context.startAbility(want).then(() => {
hilog.info(0x0001, 'TAG', "Succeeded in starting Ability successfully.")
}).catch((error: BusinessError) => {
hilog.error(0x0001, 'TAG', `Failed to startAbility.Code: ${error.code}, message is ${error.message}`);
});
}
@Entry
@Component
struct StartAppGalleryDetailAbilityView {
@State message: string = '拉起应用市场详情页';
build() {
Row() {
Column() {
Button(this.message)
.fontSize(24)
.fontWeight(FontWeight.Bold)
.onClick(() => {
const context: common.UIAbilityContext = this.getUIContext().getHostContext() as common.UIAbilityContext;
// 按实际需求获取应用的bundleName,例如bundleName: 'com.huawei.hmsapp.books'
const bundleName = 'xxxx';
startAppGalleryDetailAbility(context, bundleName);
})
}
.width('100%')
}
.height('100%')
}
}
更多关于HarmonyOS 鸿蒙Next应用设置跳转华为应用市场目标APP下载页的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
在鸿蒙设备上加载该链接,为自动跳转到应用市场app下载页。若不是鸿蒙设备,会提示:

源码示例如下,以跳转到华为应用市场的wx界面举例:

跳转目标app的下载页,需要知道其包名即可。

import Want from '@ohos.app.ability.Want';
import common from '@ohos.app.ability.common';
import { BusinessError } from '@kit.BasicServicesKit';
@Entry
@Component
struct AGCStorePage {
private TAG: string = "AGCStorePage";
// 以wx举例:
@State mAppId: string = 'com.tencent.wechat';
controller: TextInputController = new TextInputController();
build() {
Row() {
Column() {
TextInput({ text: this.appId, placeholder: '请输入应用的appId', controller: this.controller })
.width('90%')
.onChange((value: string) => {
this.mAppId = value
})
Button('点击跳转到鸿蒙版应用市场详情页面')
.margin({top: 50})
.onClick(()=>{
const want: Want = {
uri: "store://appgallery.huawei.com/app/detail?id=" + this.mAppId
};
const context = getContext(this) as common.UIAbilityContext;
context.startAbility(want).then(()=>{
//拉起成功
console.log(this.TAG, "跳转成功!");
}).catch((err: BusinessError)=>{
// 拉起失败
console.log(this.TAG, "跳转失败!" + JSON.stringify(err));
});
})
}
.width('100%')
}
.height('100%')
}
}
注意: 拼接分享的应用下载页链接为(以wx举例,替换id即可跳转到目标app): https://appgallery.huawei.com/app/detail?id=com.tencent.wechat
在鸿蒙设备上加载该链接,为自动跳转到应用市场app下载页。若不是鸿蒙设备,会提示:
在HarmonyOS Next中,可通过want参数设置跳转至华为应用市场。使用ohos.ability.want定义目标APP的bundleName,并指定action为"ohos.settings.app.info"。调用startAbility时,传入包含"ability.startup.download"的parameters,可定向至应用市场下载页。需确保设备已安装华为应用市场。
在HarmonyOS Next中,应用可以通过Want和系统能力SystemCapability.Applications.AppMarket来实现跳转到华为应用市场并直达指定应用的下载详情页。这是推广或引导用户更新应用的标准方式。
核心实现步骤如下:
-
声明权限:在模块的
module.json5配置文件中,为相应的abilities添加ohos.permission.OPEN_APP_MARKET权限。{ "module": { "requestPermissions": [ { "name": "ohos.permission.OPEN_APP_MARKET" } ] } } -
构造并发送Want:在您的应用代码中,构造一个带有特定参数的
Want对象,然后使用startAbility或startAbilityForResult来触发跳转。- 跳转到指定应用详情页:关键是将
Want的uri参数设置为以appmarket://开头的特定格式。 - 参数说明:
packageName:目标应用在应用市场的包名(通常与应用的Bundle Name一致)。downloadType:固定值为app。callerId:您当前应用的Bundle Name,用于应用市场统计来源。
示例代码(ArkTS):
import { common, Want } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; let context: common.UIAbilityContext = ...; // 获取当前UIAbility的Context // 构造跳转到目标应用详情页的Want let want: Want = { uri: 'appmarket://details?id=目标应用包名&callerId=您当前应用的包名&downloadType=app' }; try { context.startAbility(want).then(() => { hilog.info(0x0000, '跳转成功'); }).catch((err: BusinessError) => { hilog.error(0x0000, '跳转失败,错误码: %{public}d', err.code); }); } catch (error) { let err: BusinessError = error as BusinessError; hilog.error(0x0000, '捕获异常,错误码: %{public}d', err.code); }将示例中的
目标应用包名和您当前应用的包名替换为实际值。 - 跳转到指定应用详情页:关键是将
重要注意事项:
- 包名准确性:
uri中的id参数必须与目标应用在华为应用市场发布的包名(Bundle Name) 完全一致,否则会跳转失败或跳转到应用市场首页。 - 网络与安装:跳转前请确保设备已安装华为应用市场且网络通畅。如果未安装应用市场,此Want将无法被解析。
- 运行环境:此功能依赖于系统提供的应用市场服务,在真机或支持该服务的官方模拟器上有效。
- 审核:上架华为应用市场的应用使用此功能需符合其相关规范。
通过以上方式,您的HarmonyOS Next应用可以稳定地引导用户至应用市场的指定页面。

