Created
April 6, 2025 11:25
-
-
Save unitycoder/2ccf089d78ced7afebdb7e0c30d9cb77 to your computer and use it in GitHub Desktop.
Unity Android Check if Device has autorotation enabled
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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