Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
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
up vote 0 down vote accepted

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.

share|improve this answer

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:

share|improve this answer
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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.