Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: How to know whether the notification panel is already open programmatically?

I wanted to know whether there is any way of knowing whether the notifications bar is open. I have the below code to open the notification bar from a program:

Object sbservice = getSystemService( "statusbar" );
Class<?> statusbarManager = Class.forName( "android.app.StatusBarManager" );
Method showsb;
if (Build.VERSION.SDK_INT >= 17) {
    showsb = statusbarManager.getMethod("expandNotificationsPanel");
}
else {
    showsb = statusbarManager.getMethod("expand");
}
showsb.invoke( sbservice );

Is there any way to know whether the panel is already open?

like image 621
user2349990 Avatar asked Mar 02 '26 14:03

user2349990


1 Answers

Add the following to your Activity:

@Override public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    // if hasFocus is false, notification panel is open.
}

Doco for this function is here.

like image 174
Chris Lacy Avatar answered Mar 05 '26 05:03

Chris Lacy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!