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

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

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

相关推荐
李坤林16 分钟前
Android Binder 详解(4) Binder 线程池
android·java·binder
PuddingSama1 小时前
Gson 很好,但在Kotlin上有更合适的序列化工具「Kotlin Serialization」
android·kotlin·gson
C雨后彩虹2 小时前
计算误码率
java·数据结构·算法·华为·面试
教程分享大师2 小时前
移动云电脑W132D安卓9当贝固件线刷机包_ROM刷机教程
android
程序之巅2 小时前
VS code 远程python代码debug
android·java·python
恋猫de小郭3 小时前
罗技鼠标因为服务器证书过期无法使用?我是如何解决 SSL 证书问题
android·前端·flutter
yongui478344 小时前
MATLAB中回归模型常用误差指标(MSE、RMSE、MAPE等)的实现方法
android·matlab·回归
莫比乌斯环4 小时前
【Android技能点】启动链路 + AMS/ATMS 基础概念掌握
android
AKA4 小时前
Android中第三方库的使用
android
城东米粉儿4 小时前
Android音视频开发基础知识指南
android