【鸿蒙Next】系统通知权限申请
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;
})
官方链接:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-notificationmanager-V5#notificationmanagerrequestenablenotification10