From 8328244ac4059707ffc88a57a97ff7bca3b80c28 Mon Sep 17 00:00:00 2001 From: heguokai <275503077@qq.com> Date: Tue, 2 Sep 2025 16:55:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0notificationContentType?= =?UTF-8?q?=E7=9A=84=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: heguokai <275503077@qq.com> --- .../ets/ets/@ohos.notificationManager.ets | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/frameworks/ets/ets/@ohos.notificationManager.ets b/frameworks/ets/ets/@ohos.notificationManager.ets index e6f76234f..41e141584 100644 --- a/frameworks/ets/ets/@ohos.notificationManager.ets +++ b/frameworks/ets/ets/@ohos.notificationManager.ets @@ -23,6 +23,7 @@ import { NotificationLongTextContent } from 'notification.notificationContent'; import { NotificationMultiLineContent } from 'notification.notificationContent'; import { NotificationPictureContent } from 'notification.notificationContent'; import { NotificationSystemLiveViewContent } from 'notification.notificationContent'; +import { NotificationContent } from 'notification.notificationContent'; import { NotificationTemplate } from 'notification.notificationTemplate'; import { DistributedOptions } from 'notification.notificationRequest'; import { NotificationLiveViewContent } from 'notification.notificationContent'; @@ -553,6 +554,33 @@ export default namespace notificationManager { } return true; } + function checkContentType(content: NotificationContent): boolean + { + let contentType = content.notificationContentType; + if (contentType !== undefined) { + let type:ContentType = contentType as ContentType; + if (type == ContentType.NOTIFICATION_CONTENT_BASIC_TEXT + && content.normal == undefined) { + return false; + } else if (type == ContentType.NOTIFICATION_CONTENT_LONG_TEXT + && content.longText == undefined) { + return false; + } else if (type == ContentType.NOTIFICATION_CONTENT_PICTURE + && content.picture == undefined) { + return false; + } else if (type == ContentType.NOTIFICATION_CONTENT_MULTILINE + && content.multiLine == undefined) { + return false; + } else if (type == ContentType.NOTIFICATION_CONTENT_SYSTEM_LIVE_VIEW + && content.systemLiveView == undefined) { + return false; + } else if (type == ContentType.NOTIFICATION_CONTENT_LIVE_VIEW + && content.liveView == undefined) { + return false; + } + } + return true; + } function isInvalidParameter(request: NotificationRequest): BusinessError { let error: BusinessError = successCallbackError @@ -564,6 +592,12 @@ export default namespace notificationManager { error = errorParamInvalid return error; } + if (request.content?.notificationContentType == undefined) { + return errorParamInvalid; + } + if (!checkContentType(request.content)) { + return errorParamInvalid; + } if (request.content?.normal !== undefined && !isInvalidContent(request.content.normal)) { return errorParamInvalid; } -- Gitee