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)