Reputation: 741
Is there a way to listen to the status bar notification when it is being pulled down?
Upvotes: 4
Views: 4752
Reputation: 40908
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
Upvotes: 3
Reputation: 38209
Take a look on Notification.Builder setDeleteIntent (since api level 11).
There is also Notification deleteIntent (since api level 1)
Upvotes: -1