[英]Get android device orientation even when autoRotation is turned off
I have an android app in which the screen orientation is set to portrait in manifest file. 我有一个Android应用程序,其中屏幕方向设置为清单文件中的肖像。 It uses a custom camera in b/w , to take a photo and I need to save the photo.
它使用黑白的自定义相机拍摄照片,我需要保存照片。
Before I save the image I have to rotate the image depending on how the user is holding the camera, so that the image gets saved in the right orientation. 在保存图像之前,我必须根据用户握持相机的方式旋转图像,以便以正确的方向保存图像。
So, is there any way by which I can get the device orientation even when my app is running in portrait mode and android "auto-rotation" feature is ON. 那么,即使我的应用程序以纵向模式运行并且android“自动旋转”功能为ON,我有什么方法可以获得设备方向。 How can I achieve this?
我怎样才能做到这一点?
You should do the rotation depending on the orientation information within the image, not depending on the device orientation. 您应该根据图像中的方向信息进行旋转,而不是取决于设备方向。
Here is some more information on how to determine the rotation. 以下是有关如何确定旋转的更多信息 。
Since this does not help, have you tried hackpod's answer here : 因为这并不能帮助,你尝试过hackpod的答案在这里 :
getResources().getConfiguration().orientation
要获得当前的设备方向,请尝试以
getWindowManager().getDefaultDisplay().getRotation();
Simply check, the height and width of the image. 只需检查图像的高度和宽度即可。 If the height is less than your width, it means the user was holding the phone horizontally, so you have to rotate it.
如果高度小于您的宽度,则表示用户正在水平握住手机,因此您必须旋转它。
I am currently using android orientation sensor to solve this problem and its working perfectly. 我目前正在使用android方向传感器来解决这个问题,并且它的工作非常完美。 Till someone gives a better working method , am accepting this as answer for other who have the same question.
直到有人给出了一个更好的工作方法,我接受这个作为其他有相同问题的人的答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.