鸿蒙设置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'

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

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

相关推荐
Lei活在当下7 小时前
【Perfetto从入门到精通】2. 使用 Perfetto 追踪/分析 APP 的 Native/Java 内存
android·性能优化·架构
愤怒的代码8 小时前
🔗 深度解析 SystemUI 进程间通信机制(一)
android·操作系统·app
爱吃大芒果8 小时前
GitCode口袋工具的部署运行教程
flutter·华为·harmonyos·gitcode
爱吃大芒果8 小时前
Flutter基础入门与核心能力构建——Widget、State与BuildContext核心解析
flutter·华为·harmonyos
RainyJiang9 小时前
聊聊协程里的 Semaphore:别让协程挤爆门口
android·kotlin
Dev7z10 小时前
在MySQL里创建数据库
android·数据库·mysql
invicinble11 小时前
mysql建立存数据的表(一)
android·数据库·mysql
似霰11 小时前
传统 Hal 开发笔记1----传统 HAL简介
android·hal
威哥爱编程12 小时前
【鸿蒙开发案例篇】鸿蒙6.0计算器实现详解
harmonyos·arkts·arkui
Zender Han12 小时前
Flutter Gradients 全面指南:原理、类型与实战使用
android·flutter·ios