dongshengcn dongshengcn - 2 years ago 144
Android Question

How to check if the rotation is locked on Android

I have an app, and I want my app to respect the rotation honer. But how to check if the rotation is locked on Android? Programmatically of course :)


Thanks imran for answer. I put it here again because I can not find anything about DEFAULT_ACCELEROMETER_ROTATION, and also there is not need to change user-permission if you just want to read a system setting. Cheers!, java.lang.String)

int str = Settings.System.getInt(Context.getContentResolver(),


Answer Source

You can check rotation if locked or not by using System Setting as:

   int str = Settings.System.getInt(context.getContentResolver(),                                    

      // rotation is Unlocked
   } else {
      // rotation is Locked


<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS"/>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download