14

I think each android device has an abitily to on/off auto-rotating function. Usually you can find it in settings->display->auto-rotate on/off. How can I read this setting state from my application? How can I access to this setting value? If you can share a code snipped i'd be very appreciate it.

KennyPowers
  • 4,925
  • 8
  • 36
  • 51
  • what did you do by getting that status of device. I mean what do you want to do exactly by getting that? – Shailendra Madda Jan 03 '14 at 11:42
  • 1
    Check on this: http://stackoverflow.com/questions/12870933/set-auto-rotate-enabled-disabled-android – Shibu4747 Jan 03 '14 at 11:46
  • 1
    Go through this [link][1] [1]: http://stackoverflow.com/questions/4908048/enable-and-disable-auto-rotate-programatically it may be useful for you – Vamshi Jan 03 '14 at 11:47

3 Answers3

32

Hope this code snippet helps you out:-

@Override      
protected void onCreate(Bundle savedInstanceState) {
    setContentView(R.layout.activity_main);
    if (android.provider.Settings.System.getInt(getContentResolver(),
            Settings.System.ACCELEROMETER_ROTATION, 0) == 1){
        Toast.makeText(getApplicationContext(), "Rotation ON", Toast.LENGTH_SHORT).show();

    }
    else{
        Toast.makeText(getApplicationContext(), "Rotation OFF", Toast.LENGTH_SHORT).show();
    }
    super.onCreate(savedInstanceState);
}
badgerr
  • 7,802
  • 2
  • 28
  • 43
Harshal Benake
  • 2,391
  • 1
  • 23
  • 40
3

Use the following code:

if (android.provider.Settings.System.getInt(getContentResolver(), android.provider.Settings.System.ACCELEROMETER_ROTATION, 0) == 1) {
    Toast.makeText(Rotation.this, "Rotation ON", Toast.LENGTH_SHORT).show();
} else {
    Toast.makeText(Rotation.this, "Rotation OFF", Toast.LENGTH_SHORT).show();
}
Adil Hussain
  • 30,049
  • 21
  • 112
  • 147
Meenal
  • 2,879
  • 5
  • 19
  • 43
0

Try this:

 public static void setAutoOrientationEnabled(ContentResolver resolver, boolean enabled)
        {
              Settings.System.putInt( context.getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, enabled ? 1 : 0);
        }
Vamshi
  • 1,495
  • 1
  • 15
  • 31