1

i am creating a screen lock app. i want to hide the status bar so that user can not see the status bar and open other applications through it. i have successfully hidden the status bar but with you drag from the top of screen it again appears.

i was following the Hide the Status Bar on Android 4.1 and Higher from android developer.

the code was :

View decorView = getWindow().getDecorView();
// Hide the status bar.
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);

so how do i don't allow the status bar to appear even if you swipe from the top of the screen.

Sagar Nayak
  • 2,138
  • 2
  • 19
  • 52

1 Answers1

0

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

Community
  • 1
  • 1
USKMobility
  • 5,721
  • 2
  • 27
  • 34