Android 拦截第三方推送的通知消息或系统消息或通知栏

在需求开发中,我们需要做到各种通知的屏蔽,系统的通知,下拉状态栏通知,第三方应用通知,前后台通知。以下是收集所有相关屏蔽和拦截、取消、隐藏,过滤等消息信息的方法尝试,根据不同需要定制修改,相信总有一个是可以做到的。

根据应用包名来实现对特定APP前台通知的屏蔽。通过分析代码,找到关键位置进行修改,测试后确认功能可行。

目前没有找到比较合适的过滤方式,如有些反常的应用却不进行拦截从而正常显示,但是可以拦截掉市面上的大多数应用

方法一:frameworks/base/services/core/java/com/android/server/am/ActiveServices.java  里面的这个方法setServiceForegroundLocked(*)

 public void setServiceForegroundLocked(ComponentName className, IBinder token,
            int id, Notification notification, boolean removeNotification) {
        final int userId = UserHandle.getCallingUserId();
        final long origId = Binder.clearCallingIdentity();
    //*/
        
    if( className.getPackageName().equals("com.sohu.inputmethod.sogou") ){//应用的包名
        
        return;
    }
    //*/

       try{
        *****
       }finally {
            Binder.restoreCallingIdentity(origId);
        }
}

方法二: /SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java

private void addEntry(Entry shadeEntry) {
-        boolean isHeadsUped = shouldPeek(shadeEntry);
+        boolean isHeadsUped = false;
         if (isHeadsUped) { <

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值