文档管理中心
指南应用服务AppGallery Kit(应用市场服务)应用评论服务

应用评论服务

通过应用评论服务,用户无需进入应用市场应用详情页,可以直接在应用内进行评论。

说明

从版本6.0.0(20)开始,支持拉起应用评论弹框。

场景介绍

开发者可以通过该接口拉起应用评论弹窗对应用进行评分及评论,无需进入应用市场应用详情页进行评论。

业务流程

  1. 用户需要在应用内评论应用。

  2. 应用调用showCommentDialog接口拉起应用评论弹窗。

  3. AppGalleryKit返回接口调用结果给应用。

  4. 应用返回评论窗口给用户。

约束与限制

应用评论服务不支持模拟器,请使用真机调试。

接口说明

应用评论服务提供以下接口,具体API说明详见接口文档

展开
接口名 描述
showCommentDialog(context: common.UIExtensionContext | common.UIAbilityContext): Promise<void> 拉起应用评论弹窗,用户可以在应用内评论应用。

开发步骤

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

    收起
    自动换行
    深色代码主题
    复制
    1. import { BusinessError } from '@kit.BasicServicesKit';
    2. import { hilog } from '@kit.PerformanceAnalysisKit';
    3. import type { common, Want } from '@kit.AbilityKit';
    4. import { commentManager} from '@kit.AppGalleryKit';
  2. 调用showCommentDialog方法拉起评论弹窗。

    收起
    自动换行
    深色代码主题
    复制
    1. try {
    2. const uiContext = this.getUIContext().getHostContext() as common.UIAbilityContext;
    3. commentManager.showCommentDialog(uiContext).then(()=>{
    4. hilog.info(0, 'TAG', 'succeeded in showing commentDialog.');
    5. }).catch((error: BusinessError<Object>) => {
    6. hilog.error(0, 'TAG', `showCommentDialog failed, Code: ${error.code}, message: ${error.message}`);
    7. });
    8. } catch (error) {
    9. hilog.error(0, 'TAG', `showCommentDialog failed, Code: ${error.code}, message: ${error.message}`);
    10. }

通过Deep Linking方式拉起写评论页

当应用需要跳转应用市场内对该应用进行评分与评论时,开发者可使用Deep Linking链接的方式拉起应用市场写评论页,通过拼接应用市场Deep Linking链接,在应用中调用或网页中点击Deep Linking链接在应用详情页拉起写评论页,用户可以在页面内进行评分与评论。

构造拼接bundleName和action的Deep Linking链接,其中bundleName为需要拉起写评论页的应用包名,action隐式指定为write-review,表示进入详情页后,下一步将拉起写评论页,其格式为:

收起
自动换行
深色代码主题
复制
  1. // bundleName为需要拉起写评论页的应用包名, action隐式指定为write-review, 表示进入详情页后, 下一步将拉起写评论页。
  2. uri: 'store://appgallery.huawei.com/app/detail?id=' + bundleName + '&action=write-review',

在应用中调用startAbility方法,拉起应用市场应用的写评论页:

收起
自动换行
深色代码主题
复制
  1. import { BusinessError } from '@kit.BasicServicesKit';
  2. import { hilog } from '@kit.PerformanceAnalysisKit';
  3. import type { common, Want } from '@kit.AbilityKit';
  4. // ...
  5. // 通过Deep Linking拉起应用市场指定的应用写评论页
  6. function startAppGalleryDetailAbility(context: common.UIAbilityContext, bundleName: string): void {
  7. let want: Want = {
  8. // 隐式指定action为ohos.want.action.appdetail
  9. action: 'ohos.want.action.appdetail',
  10. // bundleName为需要拉起写评论页的应用包名, action隐式指定为write-review, 表示进入详情页后, 下一步将拉起写评论页。
  11. uri: 'store://appgallery.huawei.com/app/detail?id=' + bundleName + '&action=write-review',
  12. };
  13. context.startAbility(want).then(() => {
  14. hilog.info(0x0001, 'TAG', 'Succeeded in starting Ability successfully.')
  15. }).catch((error: BusinessError) => {
  16. hilog.error(0x0001, 'TAG', `Failed to startAbility. Code: ${error.code}, message is ${error.message}`);
  17. });
  18. }
  19. @Entry
  20. @Component
  21. struct Index {
  22. // ...
  23. build() {
  24. Row() {
  25. Column() {
  26. // ...
  27. Button('DeepLink')
  28. .fontSize(24)
  29. .fontWeight(FontWeight.Bold)
  30. .onClick(() => {
  31. const context: common.UIAbilityContext = this.getUIContext().getHostContext() as common.UIAbilityContext;
  32. // 按实际需求获取应用的bundleName, 例如bundleName: 'com.huawei.hmsapp.books'
  33. const bundleName = 'xxxx';
  34. startAppGalleryDetailAbility(context, bundleName);
  35. })
  36. // ...
  37. }
  38. .width('100%')
  39. }
  40. .height('100%')
  41. }
  42. }

在网页中打开Deep Linking链接拉起应用市场应用的写评论页:

收起
自动换行
深色代码主题
复制
  1. <html lang="en">
  2. <head>
  3. <meta charset="UTF-8">
  4. </head>
  5. <body>
  6. <div>
  7. <button type="button" onclick="openDeepLink()">通过Deep Linking拉起应用市场写评论页</button>
  8. </div>
  9. </body>
  10. </html>
  11. <script>
  12. function openDeepLink() {
  13. window.open('store://appgallery.huawei.com/app/detail?id=com.xxxx.xxxx&action=write-review')
  14. }
  15. </script>

通过App Linking方式拉起写评论页

当应用需要跳转应用市场内对该应用进行评分与评论时,开发者可使用App Linking链接的方式拉起应用市场写评论页,通过拼接应用市场App Linking链接,在应用中调用或网页中点击App Linking链接在应用详情页拉起写评论页,用户可以在页面内进行评分与评论。

构造拼接bundleName的App Linking链接,其中bundleName为需要拉起写评论页的应用包名,action隐式指定为write-review,表示进入详情页后,下一步将拉起写评论页,其格式为:

收起
自动换行
深色代码主题
复制
  1. let link: string = 'https://xxx/app/detail?id=' + bundleName + '&action=write-review';

在应用中调用openLink接口拉起App Linking链接:

收起
自动换行
深色代码主题
复制
  1. import { BusinessError } from '@kit.BasicServicesKit';
  2. import { hilog } from '@kit.PerformanceAnalysisKit';
  3. import type { common, Want } from '@kit.AbilityKit';
  4. // ...
  5. @Entry
  6. @Component
  7. struct Index {
  8. // ...
  9. build() {
  10. // ...
  11. Button('start app linking', { type: ButtonType.Capsule, stateEffect: true })
  12. .width('87%')
  13. .height('5%')
  14. .margin({ bottom: '12vp' })
  15. .onClick(() => {
  16. let context: common.UIAbilityContext = this.getUIContext().getHostContext() as common.UIAbilityContext;
  17. // 需要拼接不同的应用包名,用以打开不同的应用写评论页,例如:bundleName: 'com.huawei.hmsapp.books'
  18. let bundleName: string = 'xxxx';
  19. let link: string = 'https://xxx/app/detail?id=' + bundleName + '&action=write-review';
  20. // 以App Linking优先的方式在应用市场打开指定包名的应用写评论页
  21. context.openLink(link, { appLinkingOnly: false })
  22. .then(() => {
  23. hilog.info(0x0001, 'TAG', 'openlink success.');
  24. })
  25. .catch((error: BusinessError) => {
  26. hilog.error(0x0001, 'TAG', `openlink failed. Code: ${error.code}, message is ${error.message}`);
  27. });
  28. })
  29. // ...
  30. }
  31. }

在网页中打开App Linking链接:

收起
自动换行
深色代码主题
复制
  1. <html lang="en">
  2. <head>
  3. <meta charset="UTF-8">
  4. <title>跳转示例</title>
  5. </head>
  6. <body>
  7. <a href='https://appgallery.huawei.com/app/detail?id=bundleName&action=write-review'>通过AppLinking拉起应用市场写评论页</a>
  8. </body>
  9. </html>
在 指南 中进行搜索
请输入您想要搜索的关键词