1/* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import notification from '@ohos.notificationManager' 17import { WantAgent } from '@ohos.wantAgent' 18 19class NotificationRequestUtil { 20 /** 21 * init basic NotificationRequest 22 * @param notificationContent 23 * @return return the created NotificationRequest 24 */ 25 initBasicNotificationRequest(notificationContent: notification.NotificationContent) { 26 return { 27 slotType: notification.SlotType.CONTENT_INFORMATION, 28 id: 1, // 通知id,默认为1 29 content: notificationContent 30 } 31 } 32 33 /** 34 * init wantAgent NotificationRequest 35 * @param notificationContent 36 * @param notificationWantAgent 37 * @return return the created NotificationRequest 38 */ 39 initWantAgentNotificationRequest(notificationContent: notification.NotificationContent, notificationWantAgent: WantAgent) { 40 return { 41 slotType: notification.SlotType.CONTENT_INFORMATION, 42 id: 1, // 通知id,默认为1 43 content: notificationContent, 44 wantAgent: notificationWantAgent 45 } 46 } 47 48 49 /** 50 * init NotificationRequest width buttons 51 * @param notificationContent 52 * @param notificationActionButtons 53 * @return return the created NotificationRequest 54 */ 55 initButtonNotificationRequest(notificationContent: notification.NotificationContent, notificationActionButtons: notification.NotificationActionButton[]) { 56 let actionButtons = notificationActionButtons 57 if (notificationActionButtons.length > 2) { // 当前通知接口最大允许有两个按钮,超过两个按钮不展示 58 actionButtons = notificationActionButtons.splice(0, 2) 59 } 60 return { 61 slotType: notification.SlotType.CONTENT_INFORMATION, 62 id: 1, // 通知id,默认为1 63 content: notificationContent, 64 actionButtons: actionButtons 65 } 66 } 67} 68 69export let notificationRequestUtil = new NotificationRequestUtil()