Android O新增的一个特性,系统会在通知栏显示当前在后台运行的应用,其实际是显示启动了前台服务的应用,并且当前应用的Activity不在前台。
有个需求,需要屏蔽个别APP的前台通知显示。
首先想到的就是根据包名来区分是否显示,分析代码后,定位到修改的地方:
frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationFilter.java
|| showNotificationEvenIfUnprovisioned(sbn))) {
return true;
}
+ if("com.xxx.xxx".equals(sbn.getPackageName())) {
+ return true;
+ }
if (!mKeyguardEnvironment.isNotificationForCurrentProfiles(sbn)) {
return true;
}
测试可用。