【HarmonyOS NEXT】鸿蒙跳转华为应用市场目标APP下载页

【HarmonyOS NEXT】鸿蒙跳转华为应用市场目标APP下载页

一、问题背景:

如今,大家都离不开各种手机应用。随着鸿蒙系统用户越来越多,大家都希望能在鸿蒙设备上快速找到想用的 APP。华为应用市场里有海量的 APP,但之前从鸿蒙设备进入应用市场找特定 APP 的过程有点繁琐。

从开发角度来说,打通鸿蒙设备到华为应用市场目标 APP 下载页的直接跳转,能优化整个开发链路。从产品需求出发,这能提升应用分发的效率,助力产品推广。

站在用户体验方面,这么做能大大节省用户找 APP 的时间,让大家更快下载想用的应用,极大地提升用户使用鸿蒙设备获取应用的体验。所以,实现这个跳转功能十分必要。

二、解决方案:

源码示例如下,以跳转到华为应用市场的wx界面举例:

跳转目标app的下载页,需要知道其包名即可。 点击跳转按钮后的效果:

dart 复制代码
import Want from '@ohos.app.ability.Want';
import common from '@ohos.app.ability.common';
import { BusinessError } from '@kit.BasicServicesKit';

@Entry
@Component
struct AGCStorePage {
  private TAG: string = "AGCStorePage";

  // 以wx举例:
  @State mAppId: string = 'com.tencent.wechat';
  controller: TextInputController = new TextInputController();

  build() {
    Row() {
      Column() {
        TextInput({ text: this.appId, placeholder: '请输入应用的appId', controller: this.controller })
          .width('90%')
          .onChange((value: string) => {
            this.mAppId = value
          })

        Button('点击跳转到鸿蒙版应用市场详情页面')
          .margin({top: 50})
          .onClick(()=>{
            const want: Want = {
              uri: "store://appgallery.huawei.com/app/detail?id=" + this.mAppId
            };
            const context = getContext(this) as common.UIAbilityContext;
            context.startAbility(want).then(()=>{
              //拉起成功
              console.log(this.TAG, "跳转成功!");
            }).catch((err: BusinessError)=>{
              // 拉起失败
              console.log(this.TAG, "跳转失败!" + JSON.stringify(err));
            });
          })
      }
      .width('100%')
    }
    .height('100%')
  }
}

注意: 拼接分享的应用下载页链接为(以wx举例,替换id即可跳转到目标app): appgallery.huawei.com/app/detail?...

在鸿蒙设备上加载该链接,为自动跳转到应用市场app下载页。若不是鸿蒙设备,会提示:

相关推荐
nashane13 小时前
HarmonyOS 6学习:旋转动画优化与长截图性能调优——打造丝滑交互体验的深度实践
学习·交互·harmonyos·harmonyos 5
南村群童欺我老无力.18 小时前
鸿蒙自定义组件接口设计的向后兼容陷阱
华为·harmonyos
liulian091619 小时前
Flutter 跨平台路由与状态管理:go_router 与 Riverpod 的 OpenHarmony总结
flutter·华为·学习方法·harmonyos
liulian091620 小时前
Flutter for OpenHarmony 跨平台技术实战:flutter_animate 与 pull_to_refresh 库的鸿蒙化适配总结
flutter·华为·学习方法·harmonyos
南村群童欺我老无力.20 小时前
鸿蒙PC开发的路由导航参数传递的类型安全陷阱
安全·华为·harmonyos
IntMainJhy21 小时前
【flutter for open harmony】第三方库 Flutter 二维码生成的鸿蒙化适配与实战指南
数据库·flutter·华为·sqlite·harmonyos
jiejiejiejie_1 天前
Flutter for OpenHarmony 底部选项卡与多语言适配小记:让 App 更贴心的两次小升级✨
flutter·华为·harmonyos
轻口味1 天前
HarmonyOS 6.1 全栈实战录 - 01 沉浸式视效探索:HDS 下的“光感”交互引擎深度解析与实践
华为·harmonyos
jiejiejiejie_1 天前
Flutter for OpenHarmony 应用更新检测与萌系搜索功能实战小记✨
flutter·华为·harmonyos
IntMainJhy1 天前
Flutter 三方库 Firebase Messaging 鸿蒙化适配与实战指南(权限检查+设备Token获取全覆盖)
flutter·华为·harmonyos