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

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

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

相关推荐
天空之城--24 分钟前
Android Koin 完全指南:从原理到实践
android
Hstar_chen1 小时前
开源一款 HarmonyOS 服务器监控客户端:星辰云巡 1.0.3
服务器·华为·harmonyos
zhangphil2 小时前
Android main thread主线程Choreographer doFrame发生FullSuspendCheck
android
TimeFine5 小时前
智能眼镜开发:获取真实的音频路由
android
pengyu6 小时前
【Kotlin 协程修仙录 · 渡劫境 · 中阶】 | 造化神兵:自定义 CoroutineDispatcher 与调度器的终极定制
android·kotlin
pengyu6 小时前
【Kotlin 协程修仙录 · 渡劫境 · 初阶】 | 飞升雷劫:CPS 变换与挂起函数字节码终极透视
android·kotlin
TimeFine6 小时前
智能眼镜开发:眼镜Touch后收音与触发播放系统音乐的矛盾处理
android
TimeFine7 小时前
智能眼镜开发:眼镜侧收集音频
android
又见情义7 小时前
Android 系统设置从平板版迁移至TV版实践
android
2501_919749038 小时前
华为鸿蒙免费视频播放器APP—小羊免费播放器
华为·harmonyos·鸿蒙