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

前言

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

应用评论服务

这里要介绍是beta 2 推出的 应用评论服务功能,用户无需进入应用市场应用详情页,可直接在应用内进行评论。

指南:developer.huawei.com/consumer/cn...

API:developer.huawei.com/consumer/cn...

接入步骤

  1. 用户需要在应用内评论应用。
  2. 应用调用showCommentDialog接口拉起应用评论弹窗。
  3. AppGalleryKit返回接口调用结果给应用。
  4. 应用返回评论窗口给用户。

开发步骤

  1. 导入commentManager模块及相关公共模块。

    python 复制代码
    import { commentManager} from '@kit.AppGalleryKit';
    import { hilog } from '@kit.PerformanceAnalysisKit';
    import { BusinessError } from '@kit.BasicServicesKit';
    import type { common } from '@kit.AbilityKit';
  2. 调用showCommentDialog方法拉起评论弹窗。

    javascript 复制代码
    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}`);
    }
  3. 注意事项

  4. 需要使用真机

  5. 真机需要登录华为账号

  6. 一年内评论过的不能再次评论

  7. 常见错误

    错误码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.

总结

这样就可以在你的项目中接入应用评论服务了。

相关推荐
五月君_1 分钟前
炸裂!Claude Opus 4.6 与 GPT-5.3 同日发布:前端人的“自动驾驶“时刻到了?
前端·gpt
Mr Xu_5 分钟前
前端开发中CSS代码的优化与复用:从公共样式提取到CSS变量的最佳实践
前端·css
一只大侠的侠36 分钟前
Flutter开源鸿蒙跨平台训练营 Day9分类数据的获取与渲染实现
flutter·开源·harmonyos
鹏北海-RemHusband42 分钟前
从零到一:基于 micro-app 的企业级微前端模板完整实现指南
前端·微服务·架构
LYFlied42 分钟前
AI大时代下前端跨端解决方案的现状与演进路径
前端·人工智能
光影少年1 小时前
AI 前端 / 高级前端
前端·人工智能·状态模式
一位搞嵌入式的 genius1 小时前
深入 JavaScript 函数式编程:从基础到实战(含面试题解析)
前端·javascript·函数式
anOnion1 小时前
构建无障碍组件之Alert Dialog Pattern
前端·html·交互设计
一只大侠的侠1 小时前
Flutter开源鸿蒙跨平台训练营 Day 5Flutter开发鸿蒙电商应用
flutter·开源·harmonyos
choke2331 小时前
[特殊字符] Python 文件与路径操作
java·前端·javascript