4

Is there a way to listen to the status bar notification when it is being pulled down?

Gk Mohammad Emon
  • 6,084
  • 3
  • 42
  • 42
user1471575
  • 731
  • 2
  • 15
  • 23

2 Answers2

3

1. For detecting status bar changes: you can register a listener to get notified of system UI visibility changes

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

@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

Zain
  • 37,492
  • 7
  • 60
  • 84
-1

Take a look on Notification.Builder setDeleteIntent (since api level 11).

There is also Notification deleteIntent (since api level 1)

Marek R
  • 32,568
  • 6
  • 55
  • 140
  • there was link in documentation to api level 1 see my update. – Marek R Jul 17 '12 at 10:33
  • 1
    but it is not what I want. I want to know if the user has pulled down the status bar to the end of the screen or not. – user1471575 Jul 17 '12 at 10:43
  • 1
    cool misunderstunding :). Why do you need this kind of functionality? IMO there is no such notification. You can try to find it in Android code http://grepcode.com/project/repository.grepcode.com/java/ext/com.google.android/android/ – Marek R Jul 17 '12 at 11:58
  • I can not listen to the status bar as I wish. http://stackoverflow.com/questions/10373187/android-how-to-create-a-receiver-that-listen-any-click-to-status-bar-drop-down – user1471575 Jul 17 '12 at 12:43
  • 1
    @MarekR: He is asking about the receiver when the notification bar is pulled down, not the clear action. – Mahantesh M Ambi Nov 28 '15 at 10:00