Get the orientation of your Android device even if autoRotation is disabled

I have an Android app in which the screen orientation is set to portrait in the manifest file. It uses a custom camera in b / w to take a picture, and I need to save the photo.

Before saving the image, I need to rotate the image depending on how the user holds the camera so that the image is saved in the correct orientation.

So, is there a way by which I can get the orientation of the device, even when my application is running in portrait mode, and the Android auto-rotate feature is turned on. How can I achieve this?

+4
source share
4 answers

I am currently using the Android orientation sensor to solve this problem and its performance is excellent. Until someone gives a better working method, I accept this as an answer for others who have the same question.

0
source

You must rotate depending on the orientation information inside the image, not depending on the orientation of the device.

Here's more information on how to determine a turn.

Since this does not help, try hackpod answer here :

getResources().getConfiguration().orientation
+2
source

, :

getWindowManager().getDefaultDisplay().getRotation();
+1

Just check the height and width of the image. If the height is less than your width, this means that the user is holding the phone horizontally, so you need to rotate it.

0
source

Source: https://habr.com/ru/post/1608655/


All Articles