Search code examples
androidandroid-orientation

Get device rotation when auto-rotate is off


I'm writing a camera app which disables auto-rotation during the camera preview by setting android:screenOrientation="nosensor". However, I'd still like to know the rotation of the phone when the picture is taken. getResources().getConfiguration().orientation is not specific enough, only returning portrait, landscape or square. getWindowManager().getDefaultDisplay().getRotation() is always 0 since the screen is forced to be in its default orientation - how can I get what that value would be if auto-rotation were on?


Solution

  • Use this class for receiving notifications from the SensorManager when the orientation of the device has changed.