Search code examples
androidandroid-layoutscreen-orientationandroid-screen

Get Locked Orientation


Is there a method to detect if the Auto-Rotation Lock of the device is on or off? My app needs to access that method to lock the orientation during runtime.


Solution

  • Add this in your Manifest file in your activity for the fixed orientation you want for your Activity

    android:screenOrientation="portrait"
    

    like

    <activity android:name=".Settings" android:label="@string/app_name" android:screenOrientation="portrait">
    

    or in java code you can use

    setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);