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

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

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

相关推荐
Flywith242 小时前
【每日一技】Raycast 实现 scrcpy 的快捷显示隐藏
android·前端
城西往事3 小时前
鸿蒙文件哈希流
harmonyos
Lee_xiaoming3 小时前
HarmonyOS鸿蒙开发 | ArkUI组件与布局
harmonyos·arkui
没有了遇见3 小时前
Android(Coil,Glide)大量图片加载缓存清理问题(二 Coil处理)
android
城东米粉儿3 小时前
Android Dagger2笔记
android
没有了遇见4 小时前
Android(Coil,Glide)大量图片加载缓存清理问题(一)
android
恋猫de小郭4 小时前
谷歌 Genkit Dart 正式发布:现在可以使用 Dart 和 Flutter 构建全栈 AI 应用
android·前端·flutter
曾经我也有梦想5 小时前
Day4 Kotlin 高级特性
android
simplepeng6 小时前
Compose Multiplatform 中的 Navigation 3
android
Kapaseker11 小时前
一杯美式讲完 Sealed Class
android·kotlin