This module provides the in-app review capability, allowing users to leave feedback without navigating to the app details page on AppGallery
Exceptions need to be captured when an API is called.
Since: 6.0.0(20)
showCommentDialog(context: common.UIExtensionContext | common.UIAbilityContext): Promise<void>
Launches an app review pop-up. This API uses a promise to return the result.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.AppGalleryService.Distribution.Comment
Since: 6.0.0(20)
Parameters:
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| context | common.UIExtensionContext | common.UIAbilityContext | Yes | App context. |
Returns:
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Error codes:
For details about the error codes, please refer to ArkTS API Error Codes.
| Error Code | Error Message |
|---|---|
| 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. |
Example:
import { commentManager } from '@kit.AppGalleryKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import type { common } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
@Entry
@Component
struct Index {
@State message: string = 'showCommentDialog'
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
.onClick(() => {
try {
const uiContext = this.getUIContext().getHostContext() as common.UIAbilityContext;
// Launch an app review pop-up.
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}`);
}
})
}
.width('100%')
}
.height('100%')
}
}