1.notificationManager.getActiveNotifications
支持设备Phone2in1TabletCarWearable
getActiveNotifications(callback: AsyncCallback<Array>): void
获取当前应用未删除的通知列表。使用callback异步回调。
系统能力:SystemCapability.Notification.Notification
示例
import { BusinessError } from '@kit.BasicServicesKit';
let getActiveNotificationsCallback = (err: BusinessError, data: Array<notificationManager.NotificationRequest>): void => {
if (err) {
console.error(`Failed to get active notifications. Code is ${err.code}, message is ${err.message}`);
} else {
console.info(`Succeeded in getting active notifications, data is ` + JSON.stringify(data));
}
}
notificationManager.getActiveNotifications(getActiveNotificationsCallback);
2.notificationManager.getActiveNotifications
支持设备Phone2in1TabletCarWearable
getActiveNotifications(): Promise<Array>
获取当前应用未删除的通知列表。使用Promise异步回调。
系统能力:SystemCapability.Notification.Notification
示例:
import { BusinessError } from '@kit.BasicServicesKit';
notificationManager.getActiveNotifications().then((data: Array<notificationManager.NotificationRequest>) => {
console.info(`Succeeded in getting active notifications, data is ` + JSON.stringify(data));
}).catch((err: BusinessError) => {
console.error(`Failed to get active notifications. Code is ${err.code}, message is ${err.message}`);
});
本文主要参考引用自HarmonyOS官方网站