当前位置: 首页 > news >正文

鸿蒙 应用内三种方式拉起应用市场

在应用开发中,推荐其他应用或展示当前应用的详情页是一个常见需求。通过展示应用详情页面,用户可以直达应用市场,简化下载流程,增加应用的下载量和用户活跃度。

一、方式选择

场景推荐方式
应用内打开应用市场loadProduct方式
Web页面打开应用市场App Linking方式

二、限制

限制项说明
模拟器不支持(提示:"无法获取内容,请点击屏幕重试")
设备支持Phone、Tablet、PC/2in1、TV(22+)

三、方式一:loadProduct接口调用

3.1 接口

接口描述
loadProduct(context, want, callback)加载应用详情页面接口

3.2 开发步骤

步骤1:导入模块
import { productViewManager } from '@kit.AppGalleryKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; import type { common, Want } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit';
步骤2:构造应用详情页参数
@Entry @Component struct LoadProductView { build() { Column() { Button('拉起应用市场详情页') .fontSize(24) .fontWeight(FontWeight.Bold) .onClick(() => { // 归因数据(可选) const exposureData: productViewManager.SKExposure = { adTechId: '20****e8', campaignId: '123456', destinationId: '10*******', mmpIds: ['2f****5', '2f7***5'], serviceTag: '123***2', nonce: '123***2', timestamp: 1705536488, signature: 'MEQCIEQlmZ****zKBSE8QnhLTIHZZZ****ZpRqRxHss65Ko****JgJKjdrWdkL****juEx2RmFS7da****ZRVZ8RyMyUXg==' }; const uiContext = this.getUIContext().getHostContext() as common.UIAbilityContext; const wantParam: Want = { parameters: { // 必填:要加载的应用包名 bundleName: 'com.huawei.hmsapp.books', // 可选:归因数据 skExposure: exposureData } }; const callback: productViewManager.ProductViewCallback = { onError: (error: BusinessError) => { hilog.error(0, 'TAG', `loadProduct error: ${error.code}, ${error.message}`); }, onAppear: () => { hilog.info(0, 'TAG', `loadProduct onAppear.`); }, onDisappear: () => { hilog.info(0, 'TAG', `loadProduct onDisappear.`); } }; // 调用loadProduct productViewManager.loadProduct(uiContext, wantParam, callback); }) } .width('100%') .height('100%') .justifyContent(FlexAlign.Center) } }

参数说明

参数类型必填说明
bundleNamestring要加载的应用包名
skExposureSKExposure归因数据(用于统计来源)

四、方式二:Deep Linking方式

4.1 链接格式

uri: 'store://appgallery.huawei.com/app/detail?id=' + bundleName

4.2 代码示例

import { BusinessError } from '@kit.BasicServicesKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; import type { common, Want } from '@kit.AbilityKit'; function startAppGalleryDetailAbility(context: common.UIAbilityContext, bundleName: string): void { let want: Want = { action: 'ohos.want.action.appdetail', // 隐式指定action uri: 'store://appgallery.huawei.com/app/detail?id=' + bundleName }; context.startAbility(want).then(() => { hilog.info(0x0001, 'TAG', "Succeeded in starting Ability successfully.") }).catch((error: BusinessError) => { hilog.error(0x0001, 'TAG', `Failed to startAbility. Code: ${error.code}, message: ${error.message}`); }); } @Entry @Component struct StartAppGalleryDetailAbilityView { build() { Column() { Button('拉起应用市场详情页') .onClick(() => { const context = this.getUIContext().getHostContext() as common.UIAbilityContext; const bundleName = 'com.huawei.hmsapp.books'; startAppGalleryDetailAbility(context, bundleName); }) } .width('100%') .height('100%') .justifyContent(FlexAlign.Center) } }

4.3 网页中打开Deep Linking

<html lang="en"> <head> <meta charset="UTF-8"> </head> <body> <div> <button type="button" onclick="openDeepLink()">拉起应用详情页</button> </div> </body> </html> <script> function openDeepLink() { window.open('store://appgallery.huawei.com/app/detail?id=com.xxxx.xxxx') } </script>

五、方式三:App Linking方式

5.1 链接格式

let link: string = 'https://appgallery.huawei.com/app/detail?id=' + bundleName;

5.2 代码示例

import { BusinessError } from '@kit.BasicServicesKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; import type { common } from '@kit.AbilityKit'; @Entry @Component struct Index { build() { Button('start app linking', { type: ButtonType.Capsule }) .width('87%') .height('5%') .margin({ bottom: '12vp' }) .onClick(() => { let context = this.getUIContext().getHostContext() as common.UIAbilityContext; let bundleName: string = 'com.huawei.hmsapp.books'; let link: string = 'https://appgallery.huawei.com/app/detail?id=' + bundleName; // appLinkingOnly: false 表示优先在应用市场打开,失败则用浏览器 context.openLink(link, { appLinkingOnly: false }) .then(() => { hilog.info(0x0001, 'TAG', 'openlink success.'); }) .catch((error: BusinessError) => { hilog.error(0x0001, 'TAG', `openlink failed. Code: ${error.code}, message: ${error.message}`); }); }); } }

5.3 网页中打开App Linking

<html lang="en"> <head> <meta charset="UTF-8"> <title>跳转示例</title> </head> <body> <a href='https://appgallery.huawei.com/app/detail?id=com.xxxx.xxxx'>AppLinking跳转示例</a> </body> </html>

六、三种方式对比

方式适用场景优势注意事项
loadProduct应用内拉起支持归因回调,可监听页面打开/关闭需要传入Want参数
Deep Linking应用内/网页格式简单,通用性强需要指定action
App Linking应用内/网页支持降级(失败时用浏览器打开)appLinkingOnly参数控制行为
http://www.jsqmd.com/news/755611/

相关文章:

  • Stitch:解决AI编程上下文割裂,实现跨工具记忆缝合的Python库
  • 德语NLP新突破:1540亿token开放语料库解析与应用
  • 从“可能对”到“证明对”:我是如何用Dafny给祖传算法代码上保险的
  • 别再手动跑测试了!用Jenkins+GitHub Actions自动化你的Python接口测试(附完整配置流程)
  • QKeyMapper:零门槛打造Windows终极输入控制中心,游戏办公一键切换
  • 从插槽到芯片:一文读懂PCIe 5.0扩展卡(AIC/EDSFF)所有关键引脚与电源设计
  • 【计算机网络】第7篇:IP寻址体系的演进——从分类编址到CIDR的无类域间路由
  • 量子变分激活函数在Kolmogorov-Arnold网络中的应用
  • 告别卡顿!用FCC技术优化你的OTT盒子换台体验(附RTCP消息详解)
  • TV2TV:多模态视频生成框架的技术解析与实践
  • 哈佛这项急诊研究刺痛所有白领:AI不是来替代医生的,是来淘汰“只会按流程判断”的人
  • 2026年4月热门的潮汐瀑布安装公司推荐,音乐喷泉/呐喊喷泉/旱式喷泉/波光跳泉/程控喷泉/潮汐瀑布,潮汐瀑布公司选哪家 - 品牌推荐师
  • 告别写脚本!用Python+AI搞个“超级大脑”:从RAG到Agent的硬核蜕变
  • 【限时首发】.NET 9容器安全加固手册:绕过CVE-2024-XXXX漏洞的4层防御体系
  • 【计算机网络】第8篇:IPv6协议设计的审慎与激进——地址空间、扩展头与邻居发现
  • HCNR200/201高线性模拟光耦原理与电机驱动应用
  • 大模型中转哪个技术厂家靠谱
  • GhidrAssistMCP:基于MCP协议的AI逆向工程助手实战指南
  • 为开源Agent框架Hermes配置Taotoken作为自定义模型提供商
  • 别再为百度网盘发愁了!手把手教你用Linux split命令拆分20G大文件(附完整MD5校验流程)
  • STM32软件I2C实战:MT6701与AS5600磁编码器驱动代码如何复用与快速移植
  • 基于ZYNQ的双通道矢量信号发生器的数字前端设计零中频架构【附代码】
  • Joy-Con Toolkit终极指南:5分钟掌握手柄完整优化技巧
  • AI辅助开发:让快马AI为你优化快速排序算法代码
  • 释放生产力:用快马AI一键生成你的会议纪要自动化超级技能脚本
  • 数学问题代码生成:提示模板设计与工程实践
  • 给汽车诊断新手:5分钟搞懂UDS网络层PDU(ISO15765-2)的四种帧类型
  • Vector CANape数据挖掘实战:用MF4文件里的“冷数据”驱动你的ECU优化决策
  • 大语言模型自我诊断:UCoder提升代码生成质量
  • OpenClaw 2.6.6 安装避坑与启动验证方法