How to make status bar visible on runtime with Applications built by Unity

Hi guys! :smile:

Title pretty much says it!

I’m currently developing an application, and I want to make status bar visible while running application developed by unity.

But not only that, I want to make it appear/disappear whenever I press some GUI button.

Would that be possible with unity?

The How-do-you-keep-the-status-bar-always-visible-while-an-application-runs thread explains what controls that. But to be able to control it from scripts you need to create a java plugin and call that.
In short: possible but somewhat cumbersome today; hopefully a bit easier tomorrow.

Thanks, erique, Actually I have read that thread, but as you see, I wanted to make it appear/disappear on runtime using script.
Since I’m already using enough plugins for my application, I was wondering whether I could do this without any further usage of plugin :
Thanks again anyways. XD

Sure, you just place that snippet of java code in a Java method hideStatusBar() of your existing plugin, and add a corresponding showStatusBar() method with the reverse logic. And then you call them from a script like any other Java code.

This is a super old thread, but for the sake of future Googlers, I managed to get the status bar to show (programmatically). It’s not ideal (the status bar stays on top of your content, covering it), but it’s probably what’s needed in some cases.

Small code (StatusBarChanger.cs):

class StatusBarChanger {
    private static int newStatusBarValue;

    public static void Show() {
        #if UNITY_ANDROID
            setStatusBarValue(2048); // WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN
        #endif
    }

    public static void Hide() {
        #if UNITY_ANDROID
            setStatusBarValue(1024); // WindowManager.LayoutParams.FLAG_FULLSCREEN; change this to 0 if unsatisfied
        #endif
    }

    private static void setStatusBarValue(int value) {
        newStatusBarValue = value;
        using (var unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) {
            using (var activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity")) {
                activity.Call("runOnUiThread", new AndroidJavaRunnable(setStatusBarValueInThread));
            }
        }
    }

    private static void setStatusBarValueInThread() {
        #if UNITY_ANDROID
        using (var unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) {
            using (var activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity")) {
                using (var window = activity.Call<AndroidJavaObject>("getWindow")) {
                    window.Call("setFlags", newStatusBarValue, newStatusBarValue);
                }
            }
        }
        #endif
    }
}

Usage:

StatusBartChanger.Show(); // Shows status bar on top of everything
StatusBartChanger.Hide(); // Hides status bar (default)

References that helped me:

It doesn’t hide the status bar, it only hides the notification icons (Android 4.1.2)

zeh Thx for this code

I made a popup UIDocument added to an empty GameObject as a component.

To show or hide it, I simply set the GameObject active or inactive using gameObject.SetActive(bool).