文章目录App Linking 和 DeepLink 的本质区别核心代码openLink 的 appLinkingOnly 参数绑定到 UI 点击事件两种方案完整对比一个容易踩的坑版本要求写在最后上一篇聊了 DeepLink 方案用的是store://私有协议。这篇来说说另一种方式App Linking。两种方式最终效果一样都能把用户带到应用市场的写评论页但底层逻辑完全不同。搞清楚这个差别你才能在不同场景里选对方案。App Linking 和 DeepLink 的本质区别DeepLink 走的是私有 URI 协议store://本质上是个系统内部的跳转约定出了华为生态就没用了。App Linking 走的是标准HTTPS 链接和你在浏览器里打开一个网页没什么两样——系统先尝试用已安装的应用打开打不开就降级到浏览器。这种方式的好处是可移植性更强同样的链接可以在网页、通知、分享卡片里到处用。华为应用市场的 App Linking 地址格式https://appgallery.huawei.com/app/detail?id包名actionwrite-review跟 DeepLink 的 URI 参数部分完全一致只是把store://换成了标准的https://。核心代码import{BusinessError}fromkit.BasicServicesKit;import{hilog}fromkit.PerformanceAnalysisKit;importtype{common}fromkit.AbilityKit;constTAGStartAppGalleryDetailAbilityView;// 在你的 Component 中privatecontext:common.UIAbilityContextthis.getUIContext().getHostContext()ascommon.UIAbilityContext;startDetailWithAppLinking(bundleName:string):void{letlink:stringhttps://appgallery.huawei.com/app/detail?id${bundleName}actionwrite-review;this.context.openLink(link,{appLinkingOnly:false}).then((){hilog.info(0x0001,TAG,Succeeded in starting AppLinking successfully.);}).catch((error:BusinessError){hilog.error(0x0001,TAG,Failed to start AppLinking. Code:${error.code}, message is${error.message});});}跟 DeepLink 最明显的区别是调用方法变了startAbility→openLink。openLink的appLinkingOnly参数这个参数很关键稍微解释一下this.context.openLink(link,{appLinkingOnly:false})appLinkingOnly: true严格模式只有目标应用显式配置了 App Linking 支持才能跳转否则直接报错appLinkingOnly: false宽松模式优先走 App Linking失败了会降级到浏览器或其他能处理 HTTPS 的应用华为应用市场已经完整支持 App Linking所以设false就好给自己留条退路也让跳转成功率更高。绑定到 UI 点击事件跟 DeepLink 方案一样通常挂在设置页的点击事件上Row(){Text(五星好评).fontSize(14).fontWeight(FontWeight.Medium)Image($r(app.media.advanceIcon)).width(6.74).height(12.81)}.width(85%).height(48).justifyContent(FlexAlign.SpaceBetween).onClick((){this.startDetailWithAppLinking(com.huawei.hmos.vmall);});实际项目中把包名换成你自己的就行。两种方案完整对比用了这两个方案之后总结了一下各自适合的场景场景推荐方案纯鸿蒙应用国内用户为主DeepLink更直接需要从网页/通知/消息卡片跳转App Linking兼容性好同一个链接复用到多个入口App LinkingHTTPS 链接通用对跳转速度有要求DeepLink少一层 URL 路由说实话纯在应用内触发的话两种方式体验差不多效果也一样。如果你的产品有分享功能用户可能从多渠道进入App Linking 会更灵活一点。一个容易踩的坑openLink要求传入的链接必须是合法的 HTTPS 格式不能用 HTTP也不能用自定义协议头那是 DeepLink 的活。如果你误传了store://格式的 URI会直接报错。// 错误openLink 不接受非 HTTPS 链接this.context.openLink(store://appgallery.huawei.com/...,{appLinkingOnly:false});// 正确this.context.openLink(https://appgallery.huawei.com/...,{appLinkingOnly:false});另外openLink是从 API 11 开始才有的比startAbility晚。不过我们这个项目要求 API 20完全没问题。版本要求API Version 20 Release 及以上HarmonyOS 6.0.0 Release SDK 及以上DevEco Studio 6.0.0 Release 及以上写在最后DeepLink 和 App Linking 本质上是一对互补的方案不用纠结选哪个按场景来就好。如果你的评分功能只在应用内出现两个随便选。如果以后要把这个链接放到推送通知、短信或者 H5 页面里用App Linking 的 HTTPS 格式明显更合适。下一篇会介绍第三种方案直接在应用内弹出一个评分弹窗不跳出去用户体验更流畅。