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

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

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

相关推荐
云端漫步19878 小时前
HarmonyOS 互动卡片(Live Form)入门指南:双态架构与场景动效全景解析
华为·架构·harmonyos
M-Robots echo9 小时前
安全机制架构解析:M-Robots 分层安全体系,筑牢机器人设备运行底座
机器人·ros·鸿蒙·开源社区·m-robots
阿pin12 小时前
Android随笔-kotlin withContext
android·kotlin·withcontext
树码小子12 小时前
开启 IDEA 中的断言功能
android·java·intellij-idea
Kslient12 小时前
HeaderBehavior
android
Android-Flutter14 小时前
android 动画详解
android·kotlin
OH_TPC16 小时前
HarmonyOS APP开发---“绿管家“智能植物监测App,需要用到这个库
华为·harmonyos·鸿蒙
小孔龙19 小时前
GraphicBuffer 跨进程共享
android
行业研究员19 小时前
Android内置GPS与腾讯地图定位技术对比分析
android·android定位·腾讯地图定位
云端漫步198720 小时前
HarmonyOS 互动卡片实战:快递卡片与睡眠卡片完整开发流程
华为·harmonyos