This is possible using reflection. There are plenty of problems though.
There's no way to check if the notification panel is open, or opening. So, we'll have to rely on Activity#onWindowFocusChanged(boolean). And this is where the problems begin.
public void onWindowFocusChanged (boolean hasFocus)
Called when the current Window of the activity gains or loses focus. This is the best indicator of whether this activity is visible
to the user.
Firstly, you need the EXPAND_STATUS_BAR permission:
<uses-permission android:name="android.permission.EXPAND_STATUS_BAR" />
Taken from Disable the notification panel from being pulled down
For KITKAT
We could not prevent the status appearing in full screen mode in kitkat devices, so made a hack which still suits the requirement ie block the status bar from expanding.
For that to work, the app was not made full screen. We put a overlay over status bar and consumed all input events. It prevented the status from expanding.
- customViewGroup is custom class which extends any layout(frame,relative layout etc) and consumes touch event.
- to consume touch event override the onInterceptTouchEvent method of the view group and return true
For kitkat and above, see this answer