# Disable autorotation if Android has it disabled

I'm making a game for Android in Unity. I wanted the game to handle screen rotations, so I set "Default Orientation" to "Auto Rotation. This works well, except for one issue:

If you disable auto-rotation in the device's settings, the game ignores this and keeps autorotation.

How would I go about making it disable autorotate when the Android device is set to disable autorotate?

• Let me get this straight; you want screen rotation to work in your game and you want its behaviour to be set to the device's settings? – Djentleman Jan 19 '13 at 3:09
• Exactly. If the user disables autorotation on the device, then the game shouldn't autorotate. This is how most apps seem to work. – DormoTheNord Jan 19 '13 at 5:11
• Is it possible that you're setting the rotation setting in a place that doesn't update when the device's rotation setting does? Or are you getting the rotation setting from the device every time it's needed? – Djentleman Jan 19 '13 at 7:30

I haven't tried it yet, but this might help.

Read the orientation using the platform SDK as Sundeep mentioned:

android.provider.Settings.System.getInt(getContentResolver(),Settings.System.ACCELEROMETER_ROTATION, 0)


and use the returned value to enable or disable the orientation by changing Screen.orientation to ScreenOrientation.AutoRotation or any other value as you wish.

I haven't worked with unity anytime, but a quick search turned out you can get the Android API in Unity. If it is not, take this as a way to ponder.

Try this in the activity

android.provider.Settings.System.getInt(getContentResolver(),Settings.System.ACCELEROMETER_ROTATION, 0)


If it returns 1, rotation is ON. 0 means rotation is OFF.

You can use the method putInt() if you want to change the setting.

Do not forget to set the permission:

android.permission.WRITE_SETTINGS

• This is not what the user meant. He wants to disable rotation in Unity, if the system setting is set to non-autorotate. – Panda Pajama Jan 24 '13 at 6:58
• Thanks for clarifying. However, i stated my ignorance on Unity in the first statement for the same reason. Should I delete this answer? – Sundeep Jan 24 '13 at 13:46