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

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

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

相关推荐
程序员陆业聪1 天前
2025 年客户端技术盘点与 2026 年技术展望
android
xhBruce1 天前
Android USB 存储 冷启动(开机自动插着 U 盘)场景
android·usb·vold
CheungChunChiu1 天前
在 Android 14 上使用 scrcpy 的投屏问题与解决方案
android·adb
xhBruce1 天前
Android屏幕旋转DisplayRotation - Android15
android·dms
alexhilton1 天前
使用LoRA微调Gemma实现移动端推理
android·kotlin·android jetpack
冬奇Lab1 天前
Zygote进程孵化与应用启动机制:从fork到SystemServer的完整旅程
android·源码阅读
早點睡3901 天前
高级进阶 React Native 鸿蒙跨平台开发:react-native-svg(CAPI) 矢量图形代码指南
react native·react.js·harmonyos
心中有国也有家1 天前
Flutter for OpenHarmony:Flutter 全屏滑动引擎PageView 组件详解
flutter·华为·华为云·软件工程·harmonyos
姜行运1 天前
【Linux】基础指令2
android·linux·服务器
大模型玩家七七1 天前
技术抉择:微调还是 RAG?——以春节祝福生成为例
android·java·大数据·开发语言·人工智能·算法·安全