简体   繁体   English

即使关闭autoRotation,也可以获取Android设备方向

[英]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.

相关问题 Android:即使使用 WifiLock 也会关闭 Wifi - Android: Wifi is turned off even with WifiLock 即使关闭屏幕也可以开始活动 - Start activity even when screen is turned off 关闭设备然后再打开时,AlarmManager不起作用 - AlarmManager does not work when device turned off and then turned on Android获取设备方向 - Android get Device orientation 即使Android 4.4.2中的位置服务已关闭,GetCurrentLocation仍在使用Cordova / PhoneGap App - GetCurrentLocation is working on Cordova/PhoneGap App even when the Location services are turned off in Android 4.4.2 当应用程序停止/设备关闭时,在 android 上保存片段状态/数据 - save fragment state/data on android when app stopped/device turned off 即使使用融合位置 API 关闭 GPS,如何获取位置更新? - How to get Location updates even when gps is turned off using fused location API? Android:即使设备自动旋转屏幕关闭,如何强制反转肖像方向? - Android: How to force reverse portrait orientation even if the device auto-rotate screen is off? 在Android生态系统中关闭对等设备的WiFi连接时会触发什么事件? - What event is triggered when WiFi connection of the peer device is turned off in android ecosystem? Android Xamarin 应用程序 - 如何在设备屏幕关闭然后重新打开时维护表格 state? - Android Xamarin app - how to maintain form state when device screen is turned off then back on?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM