Question: I am trying to come up with some ways of disabling the status bar without hiding it completely. This is an introlude attempt at disabling status bars in 3rd party apps. For now, I want to disable it in my own app, and then eventually create a background service to see if I can do so in other apps. The app I am creating is an operating system for children, and I am trying to develop a closed system.

Here is what I have tried. My initial idea was to monitor when status bar was accessed and then closing it. 

```
@Override
public void onWindowFocusChanged(boolean hasFocus) {
    Log.i(TAG, "onWindowFocusChanged()");
    try {
        if (!hasFocus) {
            Log.d(TAG, "close status bar attempt");
            Object service = getSystemService("statusbar");
            Class<?> statusbarManager = Class
                    .forName("android.app.StatusBarManager");
            Method collapse = statusbarManager.getMethod("collapse");
            collapse.setAccessible(true);
            collapse.invoke(service);
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

```

This is the method I used. It works for detecting when status bar is being accessed, however, it does not close the status bar once it has focus. What am I missing? Thanks in advance.

Answer: 
I have found answer to my question. First, I was missing the following permission

```
<uses-permission android:name="android.permission.EXPAND_STATUS_BAR" />

```

With that permission, the following code now works really well.

```
@Override
public void onWindowFocusChanged(boolean hasFocus) {
    Log.i(TAG, "onWindowFocusChanged()");
    try {
        if (!hasFocus) {
            Log.d(TAG, "close status bar attempt");
            //option 1
            int currentApiVersion = android.os.Build.VERSION.SDK_INT;
            Object service = getSystemService("statusbar");
            Class<?> statusbarManager = Class
                    .forName("android.app.StatusBarManager");

            if (currentApiVersion <= 16) {
                Method collapse = statusbarManager.getMethod("collapse");
                collapse.setAccessible(true);
                collapse.invoke(service);
            } else {
                Method collapse = statusbarManager.getMethod("collapsePanels");
                collapse.setAccessible(true);
                collapse.invoke(service);
            }
            // option 2
            Intent it = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
            mContext.sendBroadcast(it); 

        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

```

If you notice, there is a second option as well that I found to be working good. You can comment out option 1 if you want to use option 2, or vise versa. Both accomplish the same thing, although I believe option 2 is better.

```
Intent it = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
mContext.sendBroadcast(it); 

```

The only downfall I found is that it is slow(er) when closing. However, both methods collapse quick enough to where no one can click on any notifications or options in the status bar. Hopefully this is helpful to someone else. Good luck, Cheers!
Here's an updated answer if anyone is still looking for a solution to something like this: <https://developer.android.com/training/system-ui/immersive.html>

For me, I added the following in my onResume() method:

```
View decorView = getWindow().getDecorView();
    int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
    decorView.setSystemUiVisibility(uiOptions);

```

This allows the status bar to stay hidden but the user can still access it by swiping the edge of the screen. Then after a few seconds of inactivity it will collapse and disappear again!