【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下载页。若不是鸿蒙设备,会提示:

相关推荐
星空真迷人13 小时前
嵌入式鸿蒙并非精简版,核心究竟是什么?
stm32·单片机·嵌入式硬件·物联网·华为·harmonyos·iot
OH_TPC17 小时前
【鸿蒙优选三方库】@ohos/ijkplayer:在鸿蒙上像 B 站一样流畅播视频
华为·音视频·harmonyos·鸿蒙
2501_9197490319 小时前
华为鸿蒙经期记录APP—小羊月经
华为·harmonyos·鸿蒙
黑鲨吃西瓜1 天前
鸿蒙通用模块
harmonyos·鸿蒙
腾科IT教育1 天前
HarmonyOS开发|ArkTS UI颜色API通用规则
ui·华为·harmonyos·harmonyos开发·鸿蒙应用开发工程师
风华圆舞2 天前
HarmonyOS 自定义绘制实战 —— 用 ArkGraphics2D 画一个会卷曲翻动的页面网格
harmonyos·arkts·drawing·drawvertices·翻页卷曲·有限差分法线
风华圆舞2 天前
HarmonyOS 手势与 animator 实战 —— 捏出跟手又有弹性的翻页物理
harmonyos·手势·pixelmap·pangesture·边界回弹·native 句柄
北墨NoLimit2 天前
DevEco Code:在终端里用 AI 写鸿蒙应用
harmonyos
智塑未来2 天前
打开快、切换顺、游戏稳:鸿蒙的日常流畅表现
游戏·华为·harmonyos
智塑未来2 天前
鸿蒙游戏体验手册:四种能力从性能到玩法逐一解锁
游戏·华为·harmonyos