3
\$\begingroup\$

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?

\$\endgroup\$
3
  • \$\begingroup\$ 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? \$\endgroup\$
    – Djentleman
    Commented Jan 19, 2013 at 3:09
  • \$\begingroup\$ Exactly. If the user disables autorotation on the device, then the game shouldn't autorotate. This is how most apps seem to work. \$\endgroup\$ Commented Jan 19, 2013 at 5:11
  • \$\begingroup\$ 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? \$\endgroup\$
    – Djentleman
    Commented Jan 19, 2013 at 7:30

2 Answers 2

0
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

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
\$\endgroup\$
2
  • \$\begingroup\$ This is not what the user meant. He wants to disable rotation in Unity, if the system setting is set to non-autorotate. \$\endgroup\$ Commented Jan 24, 2013 at 6:58
  • \$\begingroup\$ Thanks for clarifying. However, i stated my ignorance on Unity in the first statement for the same reason. Should I delete this answer? \$\endgroup\$
    – Sundeep
    Commented Jan 24, 2013 at 13:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .