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

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

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

相关推荐
OH_TPC2 小时前
HarmonyOS APP开发---"菜谱汇"美食菜谱App,需要用到这个库
harmonyos
墨天梦2 小时前
D03_Compose列表与稳定身份
android·gitee·kotlin
老陈说编程2 小时前
2. 鸿蒙(HarmonyOS)超级终端与生态
华为·harmonyos
萌新杰少3 小时前
Kuikly股票查看软件开发体验——SaiRen
android·kotlin·客户端
vilya3 小时前
把 Python 塞进 APK:Chaquopy 打包实践
android·python
用户92817267390163 小时前
Android Compose版本的AI组件库来了。
android·kotlin
知昂七昂3 小时前
00-02:AOSP 源码阅读环境与检索方法论源码剖析(Android 16 / aosp-main)
android
知昂七昂3 小时前
00-01:AOSP 源码仓库结构与 repo 工作流源码剖析(Android 16 / aosp-main)
android·google
跨境数据猎手3 小时前
Android Native 层黑盒调用实战:unidbg 模拟执行 so 的原理
android
2501_919749033 小时前
华为鸿蒙免费时钟工具—小羊时钟
华为·harmonyos