【Android】SystemUI通知栏过滤指定应用的通知

需求

通知栏显示过多通知,有的是前台服务,客户反馈有的前台服务点不进去,不想让它出现在通知栏.

所以让其在添加显示时过滤掉即可。

修改

NotificationListener.java --- Android9

StatusBar.java --- Android8.1

onNotificationPosted ---- 更新通知栏通知的方法

java 复制代码
public void onNotificationPosted(final StatusBarNotification sbn,
            final RankingMap rankingMap) {
    //add isSoundNotification function to skip sound services notification 20240325
    if (sbn != null && !onPluginNotificationPosted(sbn, rankingMap) && !isSoundNotification(sbn)) {
        ....
    }
}

    //add  for skip sound notification 20240325 start
    private boolean isSoundNotification(StatusBarNotification statusBarNotification) {
        Log.i(TAG,"isSoundNotification package name = " + statusBarNotification.getPackageName());
        return statusBarNotification.getPackageName().contains("xxx.xxx.xxx");
    }
    //add  for skip sound notification 20240325 end
相关推荐
BD_Marathon7 小时前
工厂方法模式
android·java·工厂方法模式
王码码20358 小时前
Flutter for OpenHarmony:socket_io_client 实时通信的事实标准(Node.js 后端的最佳拍档) 深度解析与鸿蒙适配指南
android·flutter·ui·华为·node.js·harmonyos
勇气要爆发8 小时前
吴恩达《LangChain LLM 应用开发精读笔记》2-Models, Prompts and Parsers 模型、提示和解析器
android·笔记·langchain
Railshiqian8 小时前
给android源码下的模拟器添加两个后排屏的修改
android·开发语言·javascript
恋猫de小郭10 小时前
Flutter 的真正价值是什么?深度解析再结合鸿蒙,告诉你 Flutter 的真正优势
android·前端·flutter
Ehtan_Zheng10 小时前
我们如何在不减少功能的前提下,将安卓应用体积缩减 60%
android
QING61810 小时前
使用ADB分析CPU性能 —— 基础指南
android·前端·app
大白要努力!11 小时前
Android图片预览功能实战:从需求到上线的完整方案
android·viewpager·图片预览·实战记录·photoview
如此风景13 小时前
kotlin协程学习小计
android·kotlin
轩情吖14 小时前
MySQL初识
android·数据库·sql·mysql·adb·存储引擎