Skip to content

Instantly share code, notes, and snippets.

@marcteys
Created March 26, 2015 14:52
Show Gist options
  • Save marcteys/16b8351e392390fd66e3 to your computer and use it in GitHub Desktop.
Save marcteys/16b8351e392390fd66e3 to your computer and use it in GitHub Desktop.
FullScreenAndroid
using UnityEngine;
public class DisableSystemUI : MonoBehaviour
{
#if UNITY_ANDROID
static AndroidJavaObject activityInstance;
static AndroidJavaObject windowInstance;
static AndroidJavaObject viewInstance;
const int SYSTEM_UI_FLAG_HIDE_NAVIGATION = 2;
const int SYSTEM_UI_FLAG_LAYOUT_STABLE = 256;
const int SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION = 512;
const int SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN = 1024;
const int SYSTEM_UI_FLAG_IMMERSIVE = 2048;
const int SYSTEM_UI_FLAG_IMMERSIVE_STICKY = 4096;
const int SYSTEM_UI_FLAG_FULLSCREEN = 4;
public delegate void RunPtr();
void Start()
{
Run();
DisableNavUI();
}
public static void Run()
{
if (viewInstance != null)
{
viewInstance.Call("setSystemUiVisibility",
SYSTEM_UI_FLAG_LAYOUT_STABLE
| SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| SYSTEM_UI_FLAG_HIDE_NAVIGATION
| SYSTEM_UI_FLAG_FULLSCREEN
| SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
}
}
#endif
public static void DisableNavUI()
{
if (Application.platform != RuntimePlatform.Android)
return;
#if UNITY_ANDROID
using (AndroidJavaClass unityPlayerClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
{
activityInstance = unityPlayerClass.GetStatic<AndroidJavaObject>("currentActivity");
windowInstance = activityInstance.Call<AndroidJavaObject>("getWindow");
viewInstance = windowInstance.Call<AndroidJavaObject>("getDecorView");
AndroidJavaRunnable RunThis;
RunThis = new AndroidJavaRunnable(new RunPtr(Run));
activityInstance.Call("runOnUiThread", RunThis);
}
#endif
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment