鸿蒙设置app更新跳转华为市场

业务场景:鸿蒙调取接口检测到需要更新,跳转到应用市场更新

前提设置:在app.json5文件中设置版本号

kotlin 复制代码
  loadAppVersion() {
    appVersion().then(res => {
      if (res.code == 200) {
        let data = plainToClass(AppVersionBean, res.data as AppVersionBean)
        if (data.version > VERSION_CODE) {
          DialogHelper.showAlertDialog({
            backCancel: data.is_force != 1,
            autoCancel: data.is_force != 1,
            content: data.client_details,
            title: "应用更新",
            secondaryButton: "确认",
            onAction: (action: number, dialogId: string, content: string): void => {
              if (action == DialogAction.TWO) {
				let appId = 'com.example.shilrey'
                const want: Want = {
                  uri: `store://appgallery.huawei.com/app/detail?id=${appId}`
                };
                const context = getContext(this) as common.UIAbilityContext;
                context.startAbility(want).then(() => {
                  //拉起成功
                }).catch(() => {
                  // 拉起失败
                  showAlertMsg('应用有更新,可在应用市场更新app')
                });
              }
            }
          })
        }
      }
    })
  }

导入的依赖是这几个

kotlin 复制代码
import { VERSION_CODE } from 'BuildProfile'
import { DialogAction, DialogHelper } from '@pura/harmony-dialog'
import { common, Want } from '@kit.AbilityKit'

如果你的应用还没有在华为的鸿蒙市场上线过,跳转过去是这样的页面

这样是正常的哈,等你上架过一次就能正常跳转咯

相关推荐
2501_919749032 分钟前
鸿蒙 Flutter 实战:package_info_plus 10.1.0 适配 3.27-ohos 全流程
flutter·华为·harmonyos
大虫刷题10 分钟前
「重要通知」华为数通HCIE升级v2.0版本 考点变动 实验环境大变
华为
恋猫de小郭32 分钟前
Android 17 内存管理将严格管控,App 要注意适配
android·前端·flutter
杜子不疼.35 分钟前
[鸿蒙PC命令行移植适配]移植rust三方库tailspin到鸿蒙PC的完整实
华为·rust·harmonyos
禁默36 分钟前
[鸿蒙PC命令行移植适配]移植rust三方库pastel到鸿蒙PC的完整实践
华为·rust·harmonyos
不爱吃糖的程序媛44 分钟前
环境搭建教程:HarmonyOS PC 录屏工具(Qt5 + OHOS Native Media)
qt·华为·harmonyos
G_dou_1 小时前
Flutter三方库适配OpenHarmony【password_generator】密码生成器项目完整实战
flutter·harmonyos
赏金术士1 小时前
Android 组件化学习项目(Kotlin + AGP8+)
android·学习·kotlin
不爱吃糖的程序媛1 小时前
鸿蒙 ArkTS 编译警告消除实战:从 5 个 WARN 到 0 警告
华为·harmonyos