十行代码 带你极速接入鸿蒙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.

总结

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

相关推荐
C_心欲无痕2 分钟前
网络相关 - Ngrok内网穿透使用
运维·前端·网络
咖啡の猫3 分钟前
TypeScript-Babel
前端·javascript·typescript
行者968 分钟前
OpenHarmony平台Flutter手风琴菜单组件的跨平台适配实践
flutter·harmonyos·鸿蒙
Mintopia29 分钟前
🤖 AI 决策 + 意图OS:未来软件形态的灵魂共舞
前端·人工智能·react native
攀登的牵牛花30 分钟前
前端向架构突围系列 - 框架设计(四):依赖倒置原则(DIP)
前端·架构
Van_Moonlight30 分钟前
RN for OpenHarmony 实战 TodoList 项目:已完成未完成数量显示
javascript·开源·harmonyos
程序员爱钓鱼37 分钟前
Node.js 编程实战:测试与调试 —— 日志与监控方案
前端·后端·node.js
Mapmost1 小时前
数字孪生项目效率翻倍!AI技术实测与场景验证实录
前端
小酒星小杜1 小时前
在AI时代,技术人应该每天都要花两小时来构建一个自身的构建系统-Input篇
前端·程序员·架构