简体   繁体   English

Android:监听状态栏通知

[英]Android: listener on the status bar notification

Is there a way to listen to the status bar notification when it is being pulled down?有没有办法在下拉时收听状态栏通知?

1. For detecting status bar changes: you can register a listener to get notified of system UI visibility changes 1. 用于检测状态栏变化:您可以注册一个侦听器以获取系统 UI 可见性变化的通知

So to register the listener in your activity:因此,要在您的活动中注册侦听器:

// Detecting if the user swipe from the top down to the phone 
// screen to show up the status bar (without showing the notification area)

View decorView = getWindow().getDecorView();
decorView.setOnSystemUiVisibilityChangeListener
        (new View.OnSystemUiVisibilityChangeListener() {
            @Override
            public void onSystemUiVisibilityChange(int visibility) {
                // Note that system bars will only be "visible" if none of the
                // LOW_PROFILE, HIDE_NAVIGATION, or FULLSCREEN flags are set.
                if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
                    // The system bars are visible.

                } else {
                    // The system bars are NOT visible.

                }
            }
        });

check out this from documentation for more detail 从文档中查看更多详细信息

2. For detecting if the user pulls down the notification area of the status bar: override onWindowFocusChanged() in your activity 2. 检测用户是否下拉状态栏的通知区域:在你的activity中覆盖onWindowFocusChanged()

@Override
public void onWindowFocusChanged(boolean hasFocus) {

    if (hasFocus) { // hasFocus is true
        // the user pushed the notification bar back to the top
        Log.i("Tag", "Notification bar is pushed up");

    } else { // hasFocus is false
        // the user pulls down the notification bar
        Log.i("Tag", "Notification bar is pulled down");
    }
    super.onWindowFocusChanged(hasFocus);

}

check out the solution of Stephan Palmer in this link此链接中查看 Stephan Palmer 的解决方案

Take a look on Notification.Builder setDeleteIntent (since api level 11).查看Notification.Builder setDeleteIntent (自 api 级别 11 起)。

There is also Notification deleteIntent (since api level 1)还有Notification deleteIntent (自 api 级别 1 起)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM