问题
android:Is there a way to listen to the status bar notification when it is being pulled down?
回答1:
1. For detecting status bar changes: you can register a listener to get notified of system UI visibility changes
put below code into 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); so we could set mStatusBarShow flat to true to allow
// us hide the status bar for the next onClick event
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) {
// TODO: The system bars are visible. Make any desired
// adjustments to your UI, such as showing the action bar or
// other navigational controls.
} else {
// TODO: The system bars are NOT visible. Make any desired
// adjustments to your UI, such as hiding the action bar or
// other navigational controls.
}
}
});
check out this link 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) {
// handle when the user pull down the notification bar where
// (hasFocus will ='false') & if the user pushed the
// notification bar back to the top, then (hasFocus will ='true')
if (!hasFocus) {
Log.i("Tag", "Notification bar is pulled down");
} else {
Log.i("Tag", "Notification bar is pushed up");
}
super.onWindowFocusChanged(hasFocus);
}
check out the solution of Stephan Palmer in this link
回答2:
Take a look on Notification.Builder setDeleteIntent (since api level 11).
There is also Notification deleteIntent (since api level 1)
来源:https://stackoverflow.com/questions/11520465/android-listener-on-the-status-bar-notification