Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Disable ImmersiveMode (Unity5)

Discussion in 'Android' started by CharlesBarros, Mar 26, 2015.

  1. CharlesBarros

    CharlesBarros

    Joined:
    Nov 17, 2011
    Posts:
    61
    Is there a way to disable the immersive mode in Unity 5? It's a cool feature, but IMHO it's not right to presume that this settings is appropriated to all apps.
    I already tried unsuccessfully to set the systemUIVisibility to (View.SYSTEM_UI_FLAG_VISIBLE) and (View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) in many places of my MainActivity.

    Thanks.
     
  2. bitter

    bitter

    Unity Technologies

    Joined:
    Jan 11, 2012
    Posts:
    530
    put this in a c# script "Screen.fullScreen = false;"
     
    ismaelnascimentoash and Deanit like this.
  3. bitter

    bitter

    Unity Technologies

    Joined:
    Jan 11, 2012
    Posts:
    530
    In Unity 5.0.0p3 you can also set status bar as not hidden in player settings. This will also disable the IMMERSIVE_MODE.
     
  4. CharlesBarros

    CharlesBarros

    Joined:
    Nov 17, 2011
    Posts:
    61
    Thanks bitter! I tried so many different ways and nothing worked in a reliable way.
    Screen.fullScreen did the job! :D
     
  5. hellphil

    hellphil

    Joined:
    Oct 20, 2015
    Posts:
    1
    As of our experience, in Unity 5.2.1p4, the `status bar hidden` feature of the player settings does not work as expected. The window/application still enters the fullscreen/immersive mode.
    `Screen.fullScreen = false` works, although the scene must be loaded before the application leaves the fullscreen/immersive mode (causing the navigation and statusbar to first hide, then reappear which looks ugly).
     
    Kurt-Dekker and pordox1 like this.
  6. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,520
    Has there been any further progress on this? Is it an actual bug?

    It feels like a bug that this immersive mode feature cannot be disabled at the manifest/app launch stage, as having a status bar that flickers away, then reappears later when I say Screen.fullscreen = false; feels rather unprofessional.
     
  7. WalterBoyd

    WalterBoyd

    Joined:
    Sep 25, 2015
    Posts:
    13
    This is biting me too. Can someone confirm this is on the bug list to be fixed?
     
  8. daklab

    daklab

    Joined:
    Nov 24, 2013
    Posts:
    27
  9. Shikshen

    Shikshen

    Joined:
    Feb 21, 2015
    Posts:
    25
    Apparently, this hasn't been fixed yet, and the GitHub plugin is only a hack that doesn't work very well, at least on my device (the bar disappears and reappears instantly several times).

    Setting Screen.fullScreen = false works but the navigation bar is still hidden during the splash screen. Another problem is that Screen.width and Screen.height return the dimensions of the whole screen (navigation bar included) if called before immersive mode was effectively disabled (it is asynchronous), so my measurements on launch are wrong. I made the app assuming that the screen size never changes and this breaks several things.

    It is a bit silly that Unity deliberately activates the Immersive mode on launch without any way to control it, especially since it could probably be disabled with a simple boolean flag.

    I see that there is already PlayerSettings.defaultIsFullScreen but that doesn't work on Android. Would it be possible to enable this setting on Android as well?
     
  10. codesniper

    codesniper

    Joined:
    Mar 16, 2015
    Posts:
    1
  11. Zocker1996

    Zocker1996

    Joined:
    Jan 12, 2015
    Posts:
    20
    This will show the navigation bar (if the device has no physicall keys) and status bar after the splashscreen (if you call it in Awake) in Unity 5.6, but it will still flicker a bit. You can set the status bar color and the color in the Android overview (if the device version is over lollipop). You need to convert the Color to an argb int (not rgba).

    Code (CSharp):
    1. public static void SetupAndroidTheme (int primaryARGB, int darkARGB, string label=null)
    2.         {
    3.             #if UNITY_ANDROID && !UNITY_EDITOR
    4.             label = label??Application.productName;
    5.             Screen.fullScreen = false;
    6.             AndroidJavaObject activity = new AndroidJavaClass ("com.unity3d.player.UnityPlayer").GetStatic<AndroidJavaObject> ("currentActivity");
    7.             activity.Call ("runOnUiThread", new AndroidJavaRunnable (() => {
    8.                 AndroidJavaClass layoutParamsClass = new AndroidJavaClass ("android.view.WindowManager$LayoutParams");
    9.                 int flagFullscreen = layoutParamsClass.GetStatic<int> ("FLAG_FULLSCREEN");
    10.                 int flagNotFullscreen = layoutParamsClass.GetStatic<int> ("FLAG_FORCE_NOT_FULLSCREEN");
    11.                 int flagDrawsSystemBarBackgrounds = layoutParamsClass.GetStatic<int> ("FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS");
    12.                 AndroidJavaObject windowObject = activity.Call<AndroidJavaObject> ("getWindow");
    13.                 windowObject.Call ("clearFlags", flagFullscreen);
    14.                 windowObject.Call ("addFlags", flagNotFullscreen);
    15.                 windowObject.Call ("addFlags", flagDrawsSystemBarBackgrounds);
    16.                 int sdkInt = new AndroidJavaClass ("android.os.Build$VERSION").GetStatic<int> ("SDK_INT");
    17.                 int lollipop = 21;
    18.                 if (sdkInt > lollipop) {
    19.                     windowObject.Call ("setStatusBarColor", darkARGB);
    20.                     string myName = activity.Call<string> ("getPackageName");
    21.                     AndroidJavaObject packageManager = activity.Call<AndroidJavaObject> ("getPackageManager");
    22.                     AndroidJavaObject drawable = packageManager.Call<AndroidJavaObject> ("getApplicationIcon", myName);
    23.                     AndroidJavaObject taskDescription = new AndroidJavaObject ("android.app.ActivityManager$TaskDescription", label, drawable.Call<AndroidJavaObject> ("getBitmap"), primaryARGB);
    24.                     activity.Call ("setTaskDescription", taskDescription);
    25.                 }
    26.             }));
    27.             #endif
    28.         }
    29.  
    30. public static int ToARGB(Color color){
    31.             Color32 c = (Color32)color;
    32.             byte[] b = new byte[]{ c.b, c.g, c.r,c.a };
    33.             return System.BitConverter.ToInt32 (b, 0);
    34.         }
     
  12. goodguy

    goodguy

    Joined:
    Jul 21, 2012
    Posts:
    18
    That's just brilliant! Works like a charm for me