Search code examples
androidpreferencesetting

Check if device is locked in Portrait mode


Is there way to get information if device settings is enable to locked screen orientation?


Solution

  • You can check the value of Settings.System.ACCELEROMETER_ROTATION setting like so:

    final int rotationState = android.provider.Settings.System.getInt(
        getContentResolver(), 
        Settings.System.ACCELEROMETER_ROTATION, 0
    );
    

    When the auto-rotation is enabled, this value equals to 1 (and 0 otherwise).