Android:状态栏通知上的侦听器

Android:状态栏通知上的侦听器,android,listener,statusbar,Android,Listener,Statusbar,当状态栏被拉下时,是否有办法监听状态栏通知 看看(从api 11级开始) 还有(从api级别1开始)1。用于检测状态栏更改:您可以注册侦听器以获得系统UI可见性更改的通知 因此,要在活动中注册侦听器,请执行以下操作: // Detecting if the user swipe from the top down to the phone // screen to show up the status bar (without showing the notification area) V

当状态栏被拉下时,是否有办法监听状态栏通知

看看(从api 11级开始)


还有(从api级别1开始)1。用于检测状态栏更改:您可以注册侦听器以获得系统UI可见性更改的通知

因此,要在活动中注册侦听器,请执行以下操作:

// 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.

                }
            }
        });
查看此文件以了解更多详细信息

2。用于检测用户是否拉下状态栏的通知区域:覆盖活动中的WindowFocusChanged()

@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);

}

查看中Stephan Palmer的解决方案

文档中有指向api级别1的链接请参阅我的更新。但这不是我想要的。我想知道用户是否已将状态栏拉到屏幕的末尾。酷:)。为什么需要这种功能?海事组织没有此类通知。你可以试着在Android代码中找到它,我不能按照我的意愿收听状态栏@马雷克:当通知栏被拉下时,他问的是关于接收者的问题,而不是明确的行动。