Android 4.4 如何禁止显示通知

在PhoneStatusBar.java文件中,通过添加一个静态布尔变量NOTIFICATION来控制是否显示通知。当NOTIFICATION为false时,addNotification()方法会直接返回,阻止通知的显示。此外,代码还涉及了全屏通知的处理和Heads Up通知的动画展示逻辑。
摘要由CSDN通过智能技术生成

代码路径:
frameworks/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
在PhoneStatusBar.java文件中addNotification()就是显示通知信息,如果想禁止显示通知就可以在这里添加变量控制返回

private static final boolean NOTIFICATION = false;
public void addNotification(IBinder key, StatusBarNotification notification) {
    if (DEBUG) Log.d(TAG, "addNotification score=" + notification.getScore() +" , StatusBarNotification = " + notification +
            " , notification icon = " + notification.getNotification().icon);
    if(!NOTIFICATION){
        return;
    }
    Entry shadeEntry = createNotificationViews(key, notification);
    if (shadeEntry == null) {
        return;
    }
    if (mUseHeadsUp && shouldInterrupt(notification)) {
        if (DEBUG) Log.d(TAG, "launching notification in heads up mode");
        Entry interruptionCandidate = new Entry(key, notification, null);
        if (inflateViews(interruptionCandidate, mHeadsUpNotificationView.getHolder())) {
            mInterruptingNotificationTime = System.currentTimeMillis();
            mInterruptingNotificationEntry = interruptionCandidate;
            shadeEntry.setInterruption();

            // 1. Populate mHeadsUpNotificationView
            mHeadsUpNotificationView.setNotification(mInterruptingNotificationEntry);

            // 2. Animate mHeadsUpNotificationView in
            mHandler.sendEmptyMessage(MSG_SHOW_HEADS_UP);

            // 3. Set alarm to age the notification off
            resetHeadsUpDecayTimer();
        }
    } else if (notification.getNotification().fullScreenIntent != null) {
        // Stop screensaver if the notification has a full-screen intent.
        // (like an incoming phone call)
        awakenDreams();

        // not immersive & a full-screen alert should be shown
        if (DEBUG) Log.d(TAG, "Notification has fullScreenIntent; sending fullScreenIntent");
        try {
            notification.getNotification().fullScreenIntent.send();
        } catch (PendingIntent.CanceledException e) {
        }
    } else {
        // usual case: status bar visible & not immersive

        // show the ticker if there isn't already a heads up
        if (mInterruptingNotificationEntry == null) {
            tick(null, notification, true);
        }
    }
    addNotificationViews(shadeEntry);
    // Recalculate the position of the sliding windows and the titles.
    setAreThereNotifications();
    updateExpandedViewPos(EXPANDED_LEAVE_ALONE);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值