android:有没有办法在拉下状态栏时收听状态栏通知?
答案 0 :(得分:0)
<强> 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); so we could set mStatusBarShow flat to true to allow
// us hide the status bar for the next onClick event
boolean mStatusBarShown;
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.
mStatusBarShown = true;
} 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.
mStatusBarShown = false;
}
}
});
查看此link了解更多详情
<强> 2。用于检测用户是否拉下状态栏的通知区域:覆盖活动中的onWindowFocusChanged()
@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);
}
中查看Stephan Palmer的解决方案
答案 1 :(得分:-1)
查看Notification.Builder setDeleteIntent(自api 11级以来)。
还有Notification deleteIntent(自api级别1起)