十行代码 带你极速接入鸿蒙 6 新特性 - 应用内打分评价

前言
HarmonyOS 6 的 beta 版本来到了 beta5,也是给我们带来了不少的有趣的新特性。

应用评论服务
这里要介绍是 beta 2 推出的 应用评论服务功能,用户无需进入应用市场应用详情页,可直接在应用内进行评论。
指南:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/appgallery-comment
API:https://developer.huawei.com/consumer/cn/doc/harmonyos-references/appgallery-commentmanager

接入步骤

用户需要在应用内评论应用。
应用调用 showCommentDialog 接口拉起应用评论弹窗。
AppGalleryKit 返回接口调用结果给应用。
应用返回评论窗口给用户。
开发步骤
导入 commentManager 模块及相关公共模块。
import { commentManager} from '@kit.AppGalleryKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; import { BusinessError } from '@kit.BasicServicesKit'; import type { common } from '@kit.AbilityKit';
调用 showCommentDialog 方法拉起评论弹窗。
try { const uiContext = this.getUIContext().getHostContext() as common.UIAbilityContext; commentManager.showCommentDialog(uiContext).then(()=>{ hilog.info(0, 'TAG', "succeeded in showing commentDialog."); }).catch((error: BusinessError<Object>) => { hilog.error(0, 'TAG', `showCommentDialog failed, Code: ${error.code}, message: ${error.message}`); }); } catch (error) { hilog.error(0, 'TAG', `showCommentDialog failed, Code: ${error.code}, message: ${error.message}`); }
注意事项
需要使用真机
真机需要登录华为账号
一年内评论过的不能再次评论
常见错误
错误码 ID
错误信息
1021500001
Internal system error.
1021500002
Service request failed.
1021500003
Failed to connect to AppGallery.
1021500004
Failed to write parameters.
1021500005
The app context is invalid.
1021500006
The user has not signed in to their HUAWEI ID.
1021500007
The user has already commented on the current version.
1021500008
The number of comments has reached the maximum limit.
1021500009
The user has already left a comment, and less than a year has elapsed since then.
总结
这样就可以在你的项目中接入应用评论服务了。
以往文章
我的 iMaHarmonyOS 知识库接入 鸿蒙 6 API20 新特性了
https://mp.weixin.qq.com/s/YsbFQyi5PsndpRUaA9h_dA?token=830743671&lang=zh_CN
鸿蒙创新赛 HarmonyOS 6.0.0(20) 关键特性汇总
https://mp.weixin.qq.com/s/ERmgSAIT8B8njFqtyPx9IQ
可可图片编辑 HarmonyOS(4)图片裁剪-canvas
https://mp.weixin.qq.com/s/2M3f_LNnt0YRo0qEnCnqpA
可可图片编辑 HarmonyOS(3)应用间分享图片
https://mp.weixin.qq.com/s/n8kkdougB4lqDHjYC7co8g
近期活动
最近想要想要考取 HarmonyOS 基础或者高级证书,或者快要获取的同学都可以点击这个链接,加入我的班级,考取成功有机会获得鸿蒙礼盒一份。
https://developer.huawei.com/consumer/cn/training/classDetail/7e230b074eaa41c587c71c1d1a9a6514?type=1%3Fha_source%3Dhmosclass&ha_sourceId=89000248

联系我
可以加我微信,带你了解更多 HarmonyOS 相关的资讯。

版权声明: 本文为 InfoQ 作者【万少】的原创文章。
原文链接:【http://xie.infoq.cn/article/f885f73eecfa8819a1570f0c9】。文章转载请联系作者。
评论