androidshow-hidestatusbar

Android: show/hide status bar/power bar


I am trying to create a button where I can hide or show the status bar on my tablet.

I've put in the onCreate

getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);

and in the buttons show:

WindowManager.LayoutParams attrs = getWindow().getAttributes();
attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN;
getWindow().setAttributes(attrs);

hide:

WindowManager.LayoutParams attrs = getWindow().getAttributes();
attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
getWindow().setAttributes(attrs);

Any hints/tipps?

//edit

I've looked at this hint here: http://android.serverbox.ch/?p=306 and changed my code like this:

private void hideStatusBar() throws IOException, InterruptedException {
    Process proc = Runtime.getRuntime().exec(new String[]{"su","-c","service call activity 79 s16 com.android.systemui"});
    proc.waitFor();
}

private void showStatusBar() throws IOException, InterruptedException {
    Process proc = Runtime.getRuntime().exec(new String[]{"am","startservice","-n","com.android.systemui/.SystemUIService"});
    proc.waitFor();
}

So if I click on my buttons an the methods are called I can see that something is happening because the app is waiting some seconds. I also looked into LockCat and see that something is happening.

show: http://pastebin.com/CidTRSTi hide: http://pastebin.com/iPS6Kgbp


Solution

  • Do you have the fullscreen theme set in the manifest?

    android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
    

    I don't think you'll be able to go fullscreen without this.

    I would use the following to add and remove the fullscreen flag:

    // Hide status bar
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    // Show status bar
    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);