diff --git a/README.en.md b/README.en.md new file mode 100644 index 0000000000000000000000000000000000000000..85f9770830b9ec4ffb7e6c77221d9e75338c8ce0 --- /dev/null +++ b/README.en.md @@ -0,0 +1,81 @@ +# Custom Notification Badge + +### Overview + +This sample shows how to use the **@ohos.notificationManager** APIs to set a badge on the home screen and send and obtain notifications. + +### Preview + +| Home Page/Notification List | Notification Publishing Page | Notification Panel | +|-----------------------------------|------------------------------------------------|----------------------------------------------------| +| ![image](screenshots/main.en.png) | ![image](screenshots/notification_send.en.png) | ![image](screenshots/notification_get_list.en.png) | + +### How to Use + +1. On the home page, you can check all notifications of the current application. +2. Tap the tab in the lower right corner to access the notification publishing page and tap a button to publish the corresponding notification as required. +3. Tap the tab in the lower left corner to access the notification list, in which you can check the published notifications. The number of published notifications is displayed on the right side. Tap a notification to read or cancel it. +4. Swipe down from the notification panel to check the number of badges, which corresponds to the number of published notifications. + +### Project Directory + +``` +├──entry/src/main/ets/ +│ ├──components +│ │ ├──NotificationList.ets // Notification list control +│ │ ├──NotificationPublish.ets // Notification publishing control +│ │ └──TitleBar.ets // Title bar control +│ ├──entryability +│ │ └──EntryAbility.ets // Entry ability +│ ├──feature +│ │ └──NotificationOperations.ets // APIs for publishing notification +│ └──pages +│ └──Index.ets // Home page +├──entry/src/main/resources // Static resources of the app +│ +├──notification/src/main/ets/ +│ ├──notification +│ │ ├──NotificationContentUtil.ets // Encapsulates the main content of different notifications +│ │ ├──NotificationManagementUtil.ets // Encapsulates APIs for the notification list and badge settings +│ │ ├──NotificationRequestUtil.ets // Receives the main content of the notification and returns a complete notification +│ │ └──NotificationUtil.ets // Encapsulates APIs that allow publishing, publish and close notifications +│ └──util +│ └──Logger.ets // Log files +└──notification/src/main/resources // Static resources of the app +``` + +### How to Implement + +* The following APIs are encapsulated into the **NotificationUtil.ets** file. For details about the source code, see [NotificationUtil.ets](notification/src/main/ets/notification/NotificationUtil.ets). + * For notification request: Before accessing the [Index.ets](entry/src/main/ets/pages/Index.ets) page, + call the **notification.requestEnableNotification()** API through **notificationUtil.enableNotification()** to send a notification request to the user. + * For publishing notifications: Encapsulate the notification publishing API through **publishNotification()**. + +* The following APIs are encapsulated in the **NotificationManagementUtil.ets** file. For details about the source code, see [NotificationManagementUtil.ets](notification/src/main/ets/notification/NotificationManagementUtil.ets). + * For obtaining all application notifications: Call the **getActiveNotifications** API of @ohos.notificationManager in **constructor()** to obtain all notifications and the number of specific notifications. Then encapsulate the **getAllNotifications()** API to obtain all notifications and their quantity. + * For canceling specific notifications: Encapsulate this API through **cancelNotificationType()**. + * For badge management: Encapsulate the API for setting the badge quantity through **setBadgeNumber()** and the API for obtaining the current badge quantity through **getBadgeNumber()**. + * For adding a notification: Encapsulate this API through **addNotification()** and add a notification to the message manager. Call this API when publishing a notification. + +* The following API is encapsulated in the **NotificationOperations.ets** file. For details about the source code, see [NotificationOperations.ets](entry/src/main/ets/feature/NotificationOperations.ets). + * For publishing notifications: Access the tab page through the [Index.ets](entry/src/main/ets/pages/Index.ets) page + and call the specific method encapsulated in the **NotificationOperations.ets** when a notification is tapped. Then obtain the corresponding content from the **NotificationContentUtil.ets** + and pass it to the **NotificationRequestUtil.ets** to obtain the complete notification. Finally, call **NotificationUtil.publishNotification()** to publish the notification and **addNotification()** of the **NotificationManagementUtil.ets** to add a notification. + +### Required Permissions + +N/A + +### Dependencies + +N/A + +### Constraints + +1. The sample app is supported only on Huawei phones running the standard system. + +2. The HarmonyOS version must be HarmonyOS NEXT Developer Beta1 or later. + +3. The DevEco Studio version must be DevEco Studio NEXT Developer Beta1 or later. + +4. The HarmonyOS SDK version must be HarmonyOS NEXT Developer Beta1 or later. diff --git a/README.md b/README.md index 731fa0b81bb725ac93b29907559eab207fa6b083..a391fe32f6e03e6b55bdeea02426040a76bbb24a 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ ### 效果预览 -| 主页| 通知发送界面| 通知列表 | +| 主页/通知列表 | 通知发送界面| 通知栏 | |--------------------------------|--------------------------------|-------------------------------------------------| | ![image](screenshots/main.png) | ![image](screenshots/notification_send.png) | ![image](screenshots/notification_get_list.png) | @@ -14,8 +14,8 @@ 1. 在主界面,可以看到当前应用的所有消息通知; 2. 点击右下角Tab页签进入通知发送页面,点击对应的通知即可发送相应类型的通知,点击几次发送几条; -3. 点击左下角Tab页签进入消息列表,可以查看刚才发送的消息,消息右边会显示消息数量,点击相应的消息可进行消息读取,取消相应通知; -4. 下拉通知栏,可以看到角标数量,对应消息数量。 +3. 点击左下角Tab页签进入通知列表,可以查看刚才发送的通知,通知右边会显示通知数量,点击相应的通知可进行通知读取,取消相应通知数量; +4. 下拉通知栏,可以看到角标数量,对应的通知数量。 ### 工程目录 @@ -36,7 +36,7 @@ ├──notification/src/main/ets/ │ ├──notification │ │ ├──NotificationContentUtil.ets // 封装各种通知的主体内容 -│ │ ├──NotificationManagementUtil.ets // 封装消息列表,角标设置的接口 +│ │ ├──NotificationManagementUtil.ets // 封装通知列表,角标设置的接口 │ │ ├──NotificationRequestUtil.ets // 接收通知的主体内容,返回完整的通知 │ │ └──NotificationUtil.ets // 封装允许发布通知、发布通知、关闭通知的接口 │ └──util diff --git a/entry/src/main/ets/components/NotificationList.ets b/entry/src/main/ets/components/NotificationList.ets index d71bfc8f412b1336b185756aace68764153b3fdb..2567c0e839cae4c94aac06b3eeefc8eaa911c940 100644 --- a/entry/src/main/ets/components/NotificationList.ets +++ b/entry/src/main/ets/components/NotificationList.ets @@ -54,11 +54,9 @@ export struct NotificationList { }) }.width('100%') }.width('100%') - } } - @Component export struct NotificationItem { @State notificationNum: number = 0; @@ -104,7 +102,11 @@ export struct NotificationItem { Badge({ count: this.notificationNum, position: BadgePosition.Right, - style: { badgeSize: 16, badgeColor: $r('app.color.badge_color'), fontSize: 10 } + style: { + badgeSize: 16, + badgeColor: $r('app.color.badge_color'), + fontSize: 10 + } }) { Column() { Text(this.title) diff --git a/entry/src/main/ets/components/NotificationPublish.ets b/entry/src/main/ets/components/NotificationPublish.ets index 8514b5e43e7aa3e08c46ec338f2607cdafe141ff..bc9338be7e5a2166673a08ce4d94be3723e54a76 100644 --- a/entry/src/main/ets/components/NotificationPublish.ets +++ b/entry/src/main/ets/components/NotificationPublish.ets @@ -21,7 +21,8 @@ import { TitleBar } from './TitleBar'; export struct NoticePublish { private notificationOperations: NotificationOperations = new NotificationOperations(getContext(this)); - @Styles buttonStyle(){ + @Styles + buttonStyle(){ .width('86.7%') .height(40) .margin(6) @@ -29,7 +30,6 @@ export struct NoticePublish { } build() { - Column() { TitleBar({ title: $r('app.string.notification_publish_title') }) Blank() @@ -51,11 +51,9 @@ export struct NoticePublish { .fontSize(16) .buttonStyle(0) .onClick(this.notificationOperations.publishMultiLineNotification) - } .width('100%') .padding(12) - } Blank() diff --git a/entry/src/main/ets/components/TitleBar.ets b/entry/src/main/ets/components/TitleBar.ets index 95aadbc70d0084014d7096b3939b88fb41da1bd3..2c96ddf757f0f461c971855c21a56c0a4677d102 100644 --- a/entry/src/main/ets/components/TitleBar.ets +++ b/entry/src/main/ets/components/TitleBar.ets @@ -13,11 +13,10 @@ * limitations under the License. */ - // Page title bar @Component export struct TitleBar { - private title: string | Resource | undefined = undefined + private title: string | Resource | undefined = undefined; build() { Row() { diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets index 4d7f26fdd801b47e8f7d614060ec91d3cbc9b096..ffca9b8a4240b9e3d18c3b82e485a64bd5e0c9a9 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ets +++ b/entry/src/main/ets/entryability/EntryAbility.ets @@ -54,4 +54,4 @@ export default class EntryAbility extends UIAbility { // Ability has back to background hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); } -} +} \ No newline at end of file diff --git a/entry/src/main/ets/feature/NotificationOperations.ets b/entry/src/main/ets/feature/NotificationOperations.ets index 2554de988445f79c663f84610e9de85820af3105..15f2e91baafcdd9dca4d97c7b2b72bf833cc92fd 100644 --- a/entry/src/main/ets/feature/NotificationOperations.ets +++ b/entry/src/main/ets/feature/NotificationOperations.ets @@ -18,7 +18,8 @@ import { notificationManager } from '@kit.NotificationKit'; import { logger, notificationUtil, notificationContentUtil, notificationRequestUtil } from '@ohos/notification'; const TAG: string = 'Sample_Notification'; -const MULTI_LINE_CONTENT: Array = ['line0', 'line1', 'line2', 'line3']; // 多行文本通知的多行文本内容 +// The multi line text content of a multi line notification. +const MULTI_LINE_CONTENT: Array = ['line0', 'line1', 'line2', 'line3']; interface NOTIFICATION_GROUP_TYPE { BASIC: string @@ -27,8 +28,8 @@ interface NOTIFICATION_GROUP_TYPE { PICTURE: string CONVERSATION: string } - -const NOTIFICATION_GROUP: NOTIFICATION_GROUP_TYPE = { // 定义不同类型通知的通知组 +// Define notification groups for different types of notifications. +const NOTIFICATION_GROUP: NOTIFICATION_GROUP_TYPE = { BASIC: 'BASIC', LONG_TEXT: 'LONG_TEXT', MULTI_LINE: 'MULTI_LINE', @@ -40,7 +41,7 @@ export default class NotificationOperations { private context: Context; private basicContent: notificationManager.NotificationBasicContent; - // 在初始化函数初始化基本通知类型的参数 + // Initialize the basic notification parameters in the initialization function. constructor(context: Context) { this.context = context; let notificationTitle = ''; @@ -53,7 +54,6 @@ export default class NotificationOperations { } } - // 发布基本类型通知 publishBasicNotification = () => { try { logger.info(TAG, 'publishBasicNotification'); @@ -64,7 +64,7 @@ export default class NotificationOperations { logger.info(TAG, `publishBasicNotification error, error = ${JSON.stringify(error)}`); } } - // 发布长文本类型通知 + publishLongTextNotification = () => { try { logger.info(TAG, 'publishLongTextNotification'); @@ -78,7 +78,7 @@ export default class NotificationOperations { logger.info(TAG, `publishLongTextNotification error, error = ${JSON.stringify(error)}`); } } - // 发布多行文本类型通知 + publishMultiLineNotification = () => { try { logger.info(TAG, 'publishMultiLineNotification'); @@ -91,7 +91,7 @@ export default class NotificationOperations { logger.info(TAG, `publishMultiLineNotification error, error = ${JSON.stringify(error)}`); } } - // 发布图片类型通知 + publishPictureNotification = async () => { try { logger.info(TAG, 'publishPictureNotification'); @@ -107,7 +107,7 @@ export default class NotificationOperations { logger.info(TAG, `publishPictureNotification error, error = ${JSON.stringify(error)}`); } } - // 发布社交类型的通知 + publishConversationNotification = async () => { try { logger.info(TAG, 'publishConversationNotification'); diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index a8e75e52d624f71cc38e219b97a71e0be5300e30..6691efb5214b4aa95d88b5d3d206ca187d834fa6 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -21,32 +21,31 @@ export interface TabImage { unselectedImage: Resource, } +interface TAB_INDEX_TYPE { + MESSAGE_TAB: number + NOTIFICATION_TAB: number +}; + const MESSAGE_TAB: TabImage = { selectedImage: $r('app.media.ic_messages_filled'), unselectedImage: $r('app.media.ic_messages'), -} +}; const NOTIFICATION_TAB: TabImage = { selectedImage: $r('app.media.ic_public_send_filled'), unselectedImage: $r('app.media.ic_public_send'), -} - -interface TAB_INDEX_TYPE { - MESSAGE_TAB: number - NOTIFICATION_TAB: number -} - +}; const TAB_INDEX: TAB_INDEX_TYPE = { MESSAGE_TAB: 0, NOTIFICATION_TAB: 1 -} +}; @Entry @Component struct Index { - @State tabsIndex: number = 0 - - @Builder TabBarBuilder(index: number, item: TabImage, tabBarName: Resource) { + @State tabsIndex: number = 0; + @Builder + TabBarBuilder(index: number, item: TabImage, tabBarName: Resource) { Column() { Image(this.tabsIndex === index ? item.selectedImage : item.unselectedImage) .width(24) @@ -54,7 +53,6 @@ struct Index { .margin({ bottom: 10 }) Text(tabBarName) .fontSize(10) - } .width('100%') .padding({ top: 0, bottom: 0 }) @@ -83,7 +81,8 @@ struct Index { } .height('100%') } - .tabBar(this.TabBarBuilder(TAB_INDEX.NOTIFICATION_TAB, NOTIFICATION_TAB, $r('app.string.notification_publish_title')),) + .tabBar(this.TabBarBuilder(TAB_INDEX.NOTIFICATION_TAB, NOTIFICATION_TAB, + $r('app.string.notification_publish_title')),) } .barHeight(74) .barWidth('100%') @@ -91,8 +90,7 @@ struct Index { .onChange((index: number) => { this.tabsIndex = index }) - }.width('100%').height('100%') .backgroundColor($r('app.color.background_light_gray')) } -} +} \ No newline at end of file diff --git a/entry/src/main/resources/base/element/string.json b/entry/src/main/resources/base/element/string.json index 683e7fb77e4160f19dbf66cc19e4c37d9622dfbf..d174a7f753fc9fdbe7039e8b24cb2028ed693d99 100644 --- a/entry/src/main/resources/base/element/string.json +++ b/entry/src/main/resources/base/element/string.json @@ -62,11 +62,11 @@ }, { "name": "messages_list_title", - "value": "Messages List" + "value": "Notification List" }, { "name": "notification_publish_title", - "value": "Notifications Publish" + "value": "Notifications Publishing" }, { "name": "accept", diff --git a/entry/src/main/resources/en_US/element/string.json b/entry/src/main/resources/en_US/element/string.json index dfd58deedec3d72eadfb5dfb8a25607d062807ed..a2353251cb83c8fa2472140cc4feac79d73869d9 100644 --- a/entry/src/main/resources/en_US/element/string.json +++ b/entry/src/main/resources/en_US/element/string.json @@ -62,11 +62,11 @@ }, { "name": "messages_list_title", - "value": "Messages List" + "value": "Notification List" }, { "name": "notification_publish_title", - "value": "Notifications Publish" + "value": "Notifications Publishing" }, { "name": "accept", diff --git a/notification/src/main/ets/notification/NotificationContentUtil.ets b/notification/src/main/ets/notification/NotificationContentUtil.ets index e30511804757ee3eb50712048c207fe3459a4d99..4fd94a19609f98e8317723e8b52df60090ef7438 100644 --- a/notification/src/main/ets/notification/NotificationContentUtil.ets +++ b/notification/src/main/ets/notification/NotificationContentUtil.ets @@ -17,12 +17,12 @@ import { image } from '@kit.ImageKit'; import { notificationManager } from '@kit.NotificationKit'; interface NotificationContentUtilResultType { - notificationContentType: notificationManager.ContentType - normal?: notificationManager.NotificationBasicContent - longText?: notificationManager.NotificationLongTextContent - multiLine?: notificationManager.NotificationMultiLineContent + notificationContentType: notificationManager.ContentType, + normal?: notificationManager.NotificationBasicContent, + longText?: notificationManager.NotificationLongTextContent, + multiLine?: notificationManager.NotificationMultiLineContent, picture?: notificationManager.NotificationPictureContent -} +}; class NotificationContentUtil { /** @@ -32,8 +32,9 @@ class NotificationContentUtil { */ initBasicNotificationContent(basicContent: notificationManager.NotificationBasicContent) { let result: NotificationContentUtilResultType = { - notificationContentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, // 通知内容类型 - normal: basicContent // 基本类型通知内容 + notificationContentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, + // Basic notification content + normal: basicContent } return result; } @@ -47,16 +48,18 @@ class NotificationContentUtil { * @param notificationExpandedTitle * @return return the created NotificationContent */ - initNotificationLongTextContent(basicContent: notificationManager.NotificationBasicContent, notificationLongText: string, notificationBriefText: string, notificationExpandedTitle: string) { + initNotificationLongTextContent(basicContent: notificationManager.NotificationBasicContent, + notificationLongText: string, notificationBriefText: string, notificationExpandedTitle: string) { let result: NotificationContentUtilResultType = { - notificationContentType: notificationManager.ContentType.NOTIFICATION_CONTENT_LONG_TEXT, // 通知内容类型 + notificationContentType: notificationManager.ContentType.NOTIFICATION_CONTENT_LONG_TEXT, longText: { - title: basicContent.title, // 通知标题 - text: basicContent.text, // 通知内容 - additionalText: basicContent.additionalText ? basicContent.additionalText : '', // 通知次要内容 - longText: notificationLongText, // 通知的长文本 - briefText: notificationBriefText, // 通知概要内容,是对通知内容的总结 - expandedTitle: notificationExpandedTitle // 通知展开时的标题 + title: basicContent.title, + text: basicContent.text, + // Notification of secondary content + additionalText: basicContent.additionalText ? basicContent.additionalText : '', + longText: notificationLongText, + briefText: notificationBriefText, + expandedTitle: notificationExpandedTitle } }; return result; @@ -70,16 +73,18 @@ class NotificationContentUtil { * @param notificationLines * @return return the created NotificationContent */ - initNotificationMultiLineContent(basicContent: notificationManager.NotificationBasicContent, notificationBriefText: string, notificationLongTitle: string, notificationLines: Array) { + initNotificationMultiLineContent(basicContent: notificationManager.NotificationBasicContent, + notificationBriefText: string, notificationLongTitle: string, notificationLines: Array) { let result: NotificationContentUtilResultType = { - notificationContentType: notificationManager.ContentType.NOTIFICATION_CONTENT_MULTILINE, // 通知内容类型 + notificationContentType: notificationManager.ContentType.NOTIFICATION_CONTENT_MULTILINE, multiLine: { - title: basicContent.title, // 通知标题 - text: basicContent.text, // 通知内容 - additionalText: basicContent.additionalText ? basicContent.additionalText : '', // 通知次要内容,是对通知内容的补充 - briefText: notificationBriefText, // 通知概要内容,是对通知内容的总结 - longTitle: notificationLongTitle, // 通知展开时的标题 - lines: notificationLines // 通知的多行文本 + title: basicContent.title, + text: basicContent.text, + // Notification of secondary content + additionalText: basicContent.additionalText ? basicContent.additionalText : '', + briefText: notificationBriefText, + longTitle: notificationLongTitle, + lines: notificationLines } }; return result; @@ -93,22 +98,22 @@ class NotificationContentUtil { * @param notificationPicture * @return return the created NotificationContent */ - initNotificationPictureContent(basicContent: notificationManager.NotificationBasicContent, notificationBriefText: string, notificationExpandedTitle: string, notificationPicture: image.PixelMap) { + initNotificationPictureContent(basicContent: notificationManager.NotificationBasicContent, + notificationBriefText: string, notificationExpandedTitle: string, notificationPicture: image.PixelMap) { let result: NotificationContentUtilResultType = { - notificationContentType: notificationManager.ContentType.NOTIFICATION_CONTENT_PICTURE, // 通知内容类型 + notificationContentType: notificationManager.ContentType.NOTIFICATION_CONTENT_PICTURE, picture: { - title: basicContent.title, // 通知标题 - text: basicContent.text, // 通知内容 - additionalText: basicContent.additionalText ? basicContent.additionalText : '', // 通知次要内容,是对通知内容的补充 - briefText: notificationBriefText, // 通知概要内容,是对通知内容的总结 - expandedTitle: notificationExpandedTitle, // 通知展开时的标题 - picture: notificationPicture // 通知的图片 + title: basicContent.title, + text: basicContent.text, + additionalText: basicContent.additionalText ? basicContent.additionalText : '', + briefText: notificationBriefText, + expandedTitle: notificationExpandedTitle, + picture: notificationPicture } }; return result; } - /** * init conversation notification content * @param basicContent @@ -116,8 +121,8 @@ class NotificationContentUtil { */ initNotificationConversationContent(basicContent: notificationManager.NotificationBasicContent) { let result: NotificationContentUtilResultType = { - notificationContentType: notificationManager.ContentType.NOTIFICATION_CONTENT_CONVERSATION, // 通知内容类型 - normal: basicContent // 基本类型通知内容 + notificationContentType: notificationManager.ContentType.NOTIFICATION_CONTENT_CONVERSATION, + normal: basicContent }; return result; } diff --git a/notification/src/main/ets/notification/NotificationManagementUtil.ets b/notification/src/main/ets/notification/NotificationManagementUtil.ets index f79ebd0b25f29bc518eb65840e0b09e3561d94db..170e954c56bbf3541ce674fbee59ca408a7f5e3d 100644 --- a/notification/src/main/ets/notification/NotificationManagementUtil.ets +++ b/notification/src/main/ets/notification/NotificationManagementUtil.ets @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + import { notificationManager } from '@kit.NotificationKit'; import { logger } from '../util/Logger'; @@ -22,7 +23,7 @@ export interface getAllNotificationsResultType { countsByType: Array } -// 通知管理 +// Notification management class NotificationManagementUtil { typeNotifications: Array> = new Array(NOTIFICATION_TYPE_SIZE + 1); countsByType: Array = new Array(NOTIFICATION_TYPE_SIZE + 1); @@ -33,7 +34,7 @@ class NotificationManagementUtil { for (let i = 0; i < NOTIFICATION_TYPE_SIZE + 1; i++) { this.typeNotifications[i] = new Array(); } - // 获取当前应用所有通知 + // Get all notifications for the current application. notificationManager.getActiveNotifications().then((notifications) => { for (let i = 0; i < notifications.length; i++) { let typeId = notifications[i].content.notificationContentType; @@ -41,21 +42,21 @@ class NotificationManagementUtil { this.typeNotifications[typeId as number].push(notifications[i]); } logger.info(`getAllActiveNotifications success, data: ${JSON.stringify(notifications)}`) - // 计算角标数量 + // Calculate the number of badge. this.countsByType.forEach((num: number) => { this.badgeNum += num; }) }) } - // 取消属于该类型的通知 + // Cancel notifications of this type. cancelNotificationType(typeId: number) { this.typeNotifications[typeId].forEach(item => { notificationManager.cancel(item.id); }) } - // 设置角标 + // Display badge async setBadgeNumber(num: number) { await notificationManager.setBadgeNumber(num).then(() => { this.badgeNum = num; @@ -63,12 +64,11 @@ class NotificationManagementUtil { }); } - // 获取角标数量 getBadgeNumber(): number { return this.badgeNum; } - // 添加一条消息 + // Add a notification. async addNotification(notification: notificationManager.NotificationRequest) { const typeId: notificationManager.ContentType = notification.content.notificationContentType as notificationManager.ContentType; this.typeNotifications[typeId].push(notification); @@ -78,7 +78,7 @@ class NotificationManagementUtil { logger.info("add Message success"); } - // 获取当前所有消息及数量 + // Get all current notifications and quantities. async getAllNotifications() { let result: getAllNotificationsResultType = { groupNotifications: this.typeNotifications, diff --git a/notification/src/main/ets/notification/NotificationRequestUtil.ets b/notification/src/main/ets/notification/NotificationRequestUtil.ets index 6077378d4d951368057f493138a3b296457d53d4..598ca12eb6cce0bd9085e02847eb529c6bb40aaa 100644 --- a/notification/src/main/ets/notification/NotificationRequestUtil.ets +++ b/notification/src/main/ets/notification/NotificationRequestUtil.ets @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + import { notificationManager } from '@kit.NotificationKit'; interface NotificationRequestUtilResultType { @@ -29,7 +30,7 @@ class NotificationRequestUtil { initBasicNotificationRequest(notificationContent: notificationManager.NotificationContent) { let result: NotificationRequestUtilResultType = { slotType: notificationManager.SlotType.CONTENT_INFORMATION, - id: 1, // 通知id,默认为1 + id: 1, // Notification ID, default is 1. content: notificationContent } return result; diff --git a/notification/src/main/ets/notification/NotificationUtil.ets b/notification/src/main/ets/notification/NotificationUtil.ets index 20a034610d2638f548bb5dc2bdb4524ae13beb6b..b1aec1abe0f0220c44d68b8848b015fb4f8a6076 100644 --- a/notification/src/main/ets/notification/NotificationUtil.ets +++ b/notification/src/main/ets/notification/NotificationUtil.ets @@ -14,9 +14,9 @@ */ import { notificationManager } from '@kit.NotificationKit'; +import { BusinessError } from '@kit.BasicServicesKit'; import { logger } from '../util/Logger'; import { notificationManagement } from '../notification/NotificationManagementUtil'; -import { BusinessError } from '@kit.BasicServicesKit'; const TAG: string = 'NotificationUtilModel'; @@ -24,7 +24,7 @@ class NotificationUtil { /** * enable notification */ - private id: number = 0 + private id: number = 0; async enableNotification() { try { @@ -56,7 +56,7 @@ class NotificationUtil { try { await notificationManager.publish(notificationRequest); logger.info(TAG, `publish notification success`); - // 通知管理器添加新通知 + // Notify manager add new notification. await notificationManagement.addNotification(notificationRequest); } catch (err) { if (err) { @@ -94,4 +94,4 @@ class NotificationUtil { } } -export let notificationUtil = new NotificationUtil(); +export let notificationUtil = new NotificationUtil(); \ No newline at end of file diff --git a/screenshots/main.en.png b/screenshots/main.en.png new file mode 100644 index 0000000000000000000000000000000000000000..28753e0c2116f330d1053c0b85bdb63a1dfdadfa Binary files /dev/null and b/screenshots/main.en.png differ diff --git a/screenshots/notification_get_list.en.png b/screenshots/notification_get_list.en.png new file mode 100644 index 0000000000000000000000000000000000000000..00b3cb7f94669d47e32b2e746dc55995429a5798 Binary files /dev/null and b/screenshots/notification_get_list.en.png differ diff --git a/screenshots/notification_send.en.png b/screenshots/notification_send.en.png new file mode 100644 index 0000000000000000000000000000000000000000..4fb7af19b83acdbfc833eb1b8a88a769d81cc892 Binary files /dev/null and b/screenshots/notification_send.en.png differ