import { notificationManager } from '@kit.NotificationKit';
// 查询是否授权通知权限
notificationManager.isNotificationEnabled()
.then((isNotificationEnabled: boolean) => {
if (isNotificationEnabled) {
LoggerUtil.info("isNotificationEnabled success");
} else {
// 未授权则请求通知权限授权
notificationManager.requestEnableNotification()
.then(() => {
LoggerUtil.info(`[ANS] requestEnableNotification success`);
}).catch((err : BusinessError) => {
if(err.code === 1600004){
LoggerUtil.info(`[ANS] requestEnableNotification refused`);
} else {
LoggerUtil.error(`[ANS] requestEnableNotification failed, code is ${err.code}, message is ${err.message}`);
}
});
}
})
.catch((err : BusinessError) => {
LoggerUtil.error(`isNotificationEnabled fail: ${JSON.stringify(err)}`);
return false;
})
【鸿蒙Next】系统通知权限申请
于 2025-02-26 14:34:59 首次发布