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

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

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

相关推荐
贾伟康40 分钟前
【口算王|20】HarmonyOS ArkTS AppGallery 发布复查实战:核对包名、版本、设备、素材和离线声明
harmonyos·arkts·appgallery·应用发布·发布审核
ChinaDragon5 小时前
HarmonyOS:Web使用Dsbridge与JavaScript完成交互
harmonyos
91刘仁德5 小时前
MYSQL 事务原理及使用
android·mysql·adb
事圆则缓6 小时前
Kotlin 协程完全指南
开发语言·kotlin
一笑的小酒馆7 小时前
AndroidKMP之瀑布流实现
android
RainyJiang7 小时前
AI时代下,Android的边界正在消失
android·openai·ai编程
Android-Flutter7 小时前
android 内存抖动详解
android
思录Echo8 小时前
自助易AI数字人外挂技术剖析|如何解决政企智能客服的多端适配难题?
人工智能·华为·harmonyos
方白羽9 小时前
为什么 Android 非要用 Intent 传值?
android·ios·harmonyos
方白羽11 小时前
Android17 重写 MessageQueue,解决 Handler 隐性卡顿
android·app