HarmonyOS NEXT应用开发-Notification Kit(用户通知服务)notificationManager.getActiveNotificationCoun

鸿蒙时代
发布于 2025-5-6 17:07
浏览
0收藏

1.notificationManager.getActiveNotificationCount
支持设备Phone2in1TabletCarWearable
getActiveNotificationCount(callback: AsyncCallback<number>): void
获取当前应用未删除的通知数。使用callback异步回调。
系统能力:SystemCapability.Notification.Notification
HarmonyOS NEXT应用开发-Notification Kit(用户通知服务)notificationManager.getActiveNotificationCoun-鸿蒙开发者社区
示例:

import { BusinessError } from '@kit.BasicServicesKit';

let getActiveNotificationCountCallback = (err: BusinessError, data: number): void => {
  if (err) {
    console.error(`Failed to get active notification count. Code is ${err.code}, message is ${err.message}`);
  } else {
    console.info(`Succeeded in getting active notification count, data is ` + JSON.stringify(data));
  }
}

notificationManager.getActiveNotificationCount(getActiveNotificationCountCallback);

2.notificationManager.getActiveNotificationCount
支持设备Phone2in1TabletCarWearable
getActiveNotificationCount(): Promise<number>
获取当前应用未删除的通知数。使用Promise异步回调。
系统能力:SystemCapability.Notification.Notification
HarmonyOS NEXT应用开发-Notification Kit(用户通知服务)notificationManager.getActiveNotificationCoun-鸿蒙开发者社区
示例:

import { BusinessError } from '@kit.BasicServicesKit';

notificationManager.getActiveNotificationCount().then((data: number) => {
  console.info(`Succeeded in getting active notification count, data is ` + JSON.stringify(data));
}).catch((err: BusinessError) => {
  console.error(`Failed to get active notification count. Code is ${err.code}, message is ${err.message}`);
});

本文主要参考引用自HarmonyOS官方网站

分类
收藏
回复
举报
回复
    相关推荐