Skip to content

Instantly share code, notes, and snippets.

@unitycoder
Created April 6, 2025 11:25
Show Gist options
  • Save unitycoder/2ccf089d78ced7afebdb7e0c30d9cb77 to your computer and use it in GitHub Desktop.
Save unitycoder/2ccf089d78ced7afebdb7e0c30d9cb77 to your computer and use it in GitHub Desktop.
Unity Android Check if Device has autorotation enabled
https://discussions.unity.com/t/responsive-ui-based-on-phone-orientation-change/932381/4
static bool DeviceAutoRotationIsOn()
{
#if UNITY_ANDROID && !UNITY_EDITOR
using (var unityPlayer = new AndroidJavaClass(“com.unity3d.player.UnityPlayer”))
{
var activity = unityPlayer.GetStatic(“currentActivity”);
var systemSettings = new AndroidJavaClass(“android.provider.Settings$System”);
var contentResolver = activity.Call(“getContentResolver”);
return systemSettings.CallStatic(“getInt”, contentResolver, “accelerometer_rotation”) == 1;
}
#endif
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment