一、屏蔽SystemUI通知
SystemUI是系统级的apk,其路径为frameworks\base\packages\SystemUI,其主要功能是显示电池信号、通知面板、系统信息、以及第三方应用通知等等。这里列举屏蔽第三方应用等系统底部通知的方法:
路径:frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java

   protected NotificationData.Entry createNotificationViews(StatusBarNotification sbn) {       if (DEBUG) {           Log.d(TAG, "createNotificationViews(notification=" + sbn);           }           final StatusBarIconView iconView = createIcon(sbn);            if (条件){                return null;            }           NotificationData.Entry entry = new NotificationData.Entry(sbn, iconView);           if (!inflateViews(entry, mStackScroller)) {               handleNotificationError(sbn, "Couldn't expand RemoteViews for: " + sbn);               return null;           }           return entry;       }

从上述代码可得知,当我们不想让通知出现,只需要在createNotificationViews返回null即可。

二、屏蔽特定通知的方法
众所周知Notification就是通知类,发出的通知必然与它有关
其所在的路径为:frameworks/base/core/java/android/app/Notification.java
想要屏蔽特定的通知,可以选择获取到特定通知的内容,以此来做一个判断(假设要屏蔽aiqiyi的通知)

public static boolean isAiqiyiExist = false;  public Builder setContentText(CharSequence text) {              mText = safeCharSequence(text);              if(mText != null && mText.equals("")){                  int result = mText.toString.indexOf("aiqiyi");                  if(result != -1){                      isAiqiyiExist = true;                  }              }              return this;          }

上述代码定义isAiqiyiExist标志位,当捕捉到此类通知时,会将这个标志位为true。
Notification的显示是在NotificationManager,其路径为:frameworks/base/core/java/android/app/NotificationManager.java
当通知要显示时会调用其中的notify方法

public void notify(int id, Notification notification) {     notify(null, id, notification); }

这就是其中的notify方法,所以我们可以加判断来让它有条件的隐藏

 public void notify(int id, Notification notification) {     if(!notification.isAiqiyiExist){             notify(null, id, notification);     } }

目前就只发现这两种,未完待续。。。。

更多相关文章

  1. Android(安卓)实现微信,QQ文件在其他应用打开并获取到路径
  2. Android(安卓)选择文件并获取路径
  3. Android(安卓)NDK之JNI陷阱
  4. /mnt/sdcard与Environment.getExternalStorageDirectory()的使用
  5. Error:Execution failed for task ':demo:packageRelease'. > Un
  6. class文件生成dex文件的步骤(命令行操作)
  7. Mac删除JDK
  8. Android(安卓)Studio Checkout GitHub Error:cannot run program
  9. Android(安卓)开发中屏蔽物理键盘

随机推荐

  1. android中封装http请求
  2. 关于android studio报错Attempt to invok
  3. android使程序进程不被LMK杀死
  4. 关于百度地图Android
  5. Android 本地文件上传到服务器
  6. 初试Android基于Vuforia开发AR
  7. OpenSignal给出的Android现状分析及技巧
  8. android 自定义软键盘
  9. android菜单和对话框
  10. android 下用ant编译脚本执行批量渠道打