3

有没有办法在下拉状态栏通知时收听它?

4

2 回答 2

3

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. 检测用户是否下拉状态栏通知区域:onWindowFocusChanged()在你的activity中覆盖

@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 的解决方案

于 2018-06-02T23:25:52.180 回答
-1

看看Notification.Builder setDeleteIntent(从 api 级别 11 开始)。

还有Notification deleteIntent(从api级别1开始)

于 2012-07-17T10:28:48.407 回答