12

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,817
  • 8
  • 31
  • 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

28

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,584
  • 2
  • 26
  • 42
Harshal Benake
  • 2,429
  • 1
  • 23
  • 41
2

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
  • 27,407
  • 21
  • 100
  • 139
Meenal
  • 2,914
  • 5
  • 18
  • 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,455
  • 1
  • 14
  • 31