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

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

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

相关推荐
黄林晴几秒前
根治协程陋习!官方级协程Skill发布
android·kotlin
jiejiejiejie_9 分钟前
Flutter for OpenHarmony 底部导航栏交互优化实战
flutter·华为·交互·harmonyos
IntMainJhy11 分钟前
Flutter 三方库 share_plus 的鸿蒙化适配与实战指南
flutter·华为·harmonyos
_waylau17 分钟前
HarmonyOS 6.0升级至6.1改动点
华为·ai·harmonyos·鸿蒙·鸿蒙系统
木斯佳19 分钟前
HarmonyOS 数据可视化实战:封装自定义值机控件实操记录与复盘
信息可视化·harmonyos
李李李勃谦23 分钟前
基于鸿蒙PC多窗口架构的任务管理与番茄钟工作流实践
华为·架构·harmonyos
忡黑梨25 分钟前
eNSP_登录华为设备
运维·服务器·网络·华为·负载均衡
零度@26 分钟前
鸿蒙应用发布到华为应用市(AppGallery)的完整流程
华为·harmonyos
浪客川30 分钟前
UniFFI 跨平台开发Rust 与 Android (Kotlin) 集成
android·rust·kotlin
AirDroid_cn33 分钟前
荣耀MagicOS 10系统设备查找:关机后如何通过附近荣耀设备定位?
android·智能手机·荣耀手机