user2349990
user2349990

Reputation: 386

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?

Upvotes: 3

Views: 1934

Answers (1)

Chris Lacy
Chris Lacy

Reputation: 4462

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.

Upvotes: 4

Related Questions