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

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

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

相关推荐
帅得不敢出门4 分钟前
Android Framework关闭软件低电关机功能测试PMIC低电保护
android
熊猫钓鱼>_>11 分钟前
Kotlin Multiplatform for OpenHarmony 实战:为 Landscapist 实现图片加载适配
开发语言·kotlin·华为云·ai编程·harmonyos·鸿蒙·openharmony
CV工程师丁Sir22 分钟前
ArkWeb 手记 08|H5 权限弹窗:相机、定位授权接管
数码相机·华为·harmonyos
特立独行的猫A25 分钟前
用仓颉语言写一个漂亮的桌面音乐播放器:cj-tauri 实战
harmonyos
m0_7381858225 分钟前
Flutter 鸿蒙化实战:qr_code_scanner_plus 适配 OpenHarmony,二维码扫描
flutter·华为·harmonyos·鸿蒙
恋猫de小郭39 分钟前
Flutter + EmbeddingGemma 2,谷歌发布完全端侧的 AI Edge Foresight
android·前端·flutter
熊猫钓鱼>_>1 小时前
开源鸿蒙平台 KMP 三方库 KStore 适配全流程:从 ohosArm64 target 到真机文件持久化验证
人工智能·华为·开源·ai编程·harmonyos·openharmony·kmp
ZealSinger1 小时前
Kotlin2.4迁移context parameters
kotlin·协程·迁移·kotlin2.4
CV工程师丁Sir1 小时前
ArkWeb 手记 07|H5 文件上传:对接鸿蒙文件选择器
华为·harmonyos
Geek_Vison2 小时前
政务APP新增鸿蒙客户端,如何复用已有的业务单元?
小程序·harmonyos·mpaas·政务·小程序容器