【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
相关推荐
huwuhang1 小时前
支付宝 APP 谷歌商店版 googleplay版最新
android
User_芊芊君子2 小时前
别再乱用 ArrayList 了!这 4 个隐藏坑,90% 的 Java 开发者都踩过
android·java·数据库
冬天vs不冷2 小时前
为什么 Java 不让 Lambda 和匿名内部类修改外部变量?final 与等效 final 的真正意义
android·java·开发语言
hogenlaw3 小时前
Stream流
android·java·开发语言
常利兵4 小时前
解锁Kotlin:数据类与密封类的奇妙之旅
android·开发语言·kotlin
sunfdf5 小时前
无需密码即可解锁 Android 手机的 5 种方法
android·智能手机
Ln5x9qZC28 小时前
Laravel AI SDK 正式发布
android·人工智能·laravel
huwuhang8 小时前
跨平台电子书阅读器 | Readest最新版 安卓版+PC版全平台
android·前端·javascript
Gse0a362g10 小时前
推荐 PHP 属性(Attributes) 简洁读取 API 扩展包
android·开发语言·php
十六年开源服务商10 小时前
WordPress服务器响应时间优化终极指南2026
android·运维·服务器