android 11.0 通知栏接收app通知开关(屏蔽app通知)

在11.0定制化开发中,需要屏蔽通知栏的通知的需求,而系统所有的通知都有NotificationManager.java来负责管理,所以我们
只要NotificationManager这里面控制通知的发送就可以了

首先来了解下NoticationManager.java

NotificationManager常用方法介绍:
public void cancelAll() 移除所有通知(只是针对当前Context下的Notification)
public void cancel(int id) 移除标记为id的通知 (只是针对当前Context下的所有Notification)
public void notify(String tag ,int id, Notification notification) 将通知加入状态栏,标签为tag,标记为id
public void notify(int id, Notification notification) 将通知加入状态栏,标记为id

//设置flag位
FLAG_AUTO_CANCEL 该通知能被状态栏的清除按钮给清除掉
FLAG_NO_CLEAR 该通知能被状态栏的清除按钮给清除掉
FLAG_ONGOING_EVENT 通知放置在正在运行
FLAG_INSISTENT 是否一直进行,比如音乐一直播放,知道用户响应

常用字段:
contentIntent 设置PendingIntent对象,点击时发送该Intent
defaults 添加默认效果
flags 设置flag位,例如FLAG_NO_CLEAR等
icon 设置图标
sound 设置声音
tickerText 显示在状态栏中的文字
when 发送此通知的时间戳

通过上面的方法了解到 所有的通知都会走 public void no

猜你喜欢

转载自blog.csdn.net/baidu_41666295/article/details/124908342