当前位置: 首页 > article >正文

【鸿蒙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


http://www.kler.cn/a/565263.html

相关文章:

  • 2025 IAST工具推荐 ︱IAST工具如何赋能企业开发安全?
  • Failed to start The PHP FastCGI Process Manager.
  • NGINX配置TCP负载均衡
  • Google sheet 复制excel内容自动合并单元格问题
  • 如何看到 git 上打 tag 的时间
  • 【缓冲区】数据库备份的衍生问题,缓冲区在哪里?JVMor操作系统?(二)
  • 【R语言】Kmeans算法
  • Java SE与Java EE
  • 【入门音视频】音视频基础知识
  • 后端之JPA(EntityGraph+JsonView)
  • 2025-2-27-4.10 动态规划(0-1 背包问题)
  • 算法教程:岛的最大面积
  • 内网穿透:打破网络限制的利器
  • 从零开始自主「起身站立」,上海AI Lab发布最新控制算法,机器人:起猛了
  • Linux部署ALAS并尝试调用MAA——非Docker方式
  • 服务 ‘Sql Server VSS writer‘ (SQLWriter) 在安装 LocalDB 时无法启动
  • SpringBoot+Shiro开发登录认证功能
  • PVE 环境快速部署
  • Ollama+Cherrystudio+beg-m3+Deepseek R1 32b部署本地私人知识库(2025年2月win11版)
  • 计算机毕业设计SpringBoot+Vue.js抗疫物资管理系统(源码+文档+PPT+讲解)