简体   繁体   English

Android:即使应用程式锁定为纵向模式,也可以取得方向

[英]Android: get orientation, even if app is locked to portrait

I'm developing an android camera api app that is locked in portrait mode in the manifest file. 我正在开发一个清单文件中以肖像模式锁定的android相机api应用。

android:configChanges="orientation"
android:screenOrientation="portrait"

My problem is, when I store pictures, they are all stored in the same orientation. 我的问题是,当我存储图片时,它们都以相同的方向存储。

I would like them to be stored with the true orientation, eg. 我希望它们以真实的方向存储,例如。 my ceiling should be at the top of the stored picture, no matter how I orient my phone, if that makes any sense 无论我如何定向手机,天花板都应该在存储图片的顶部

In order to do this I have to know the orientation of the device, however it seems that when the app is locked inn portrait, all getOrientation'ish methods thinks my phone is in portrait mode, no matter the physical orientation of my phone. 为了做到这一点,我必须知道设备的方向,但是似乎当应用程序锁定为纵向模式时,所有getOrientation'ish方法都认为我的手机处于纵向模式,无论手机的物理方向如何。

Here are the ones I've tried: 这是我尝试过的:

Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
Camera.getCameraInfo(mCurrentlyUsedCamera,cameraInfo);
Log.e("debug","orientation:"+cameraInfo.orientation);

and

getResources().getConfiguration().orientation

and

this.getWindowManager().getDefaultDisplay().getRotation()

.

Any way of getting the true orientation in a portrait locked app? 有什么方法可以在人像锁定的应用程序中获得正确的方向?

.

In short - you have to use the sensors directly. 简而言之-您必须直接使用传感器。 I kinda got it working, but then I found this guy: Android: get device orientation from Azimuth, roll & pitch 我有点用,但是后来我找到了这个人: Android:从方位角,侧倾和俯仰方向获取设备方向

So I basically deleted my all my own code and implemented his utility class :) https://gist.github.com/abdelhady/501f6e48c1f3e32b253a#file-deviceorientation 所以我基本上删除了所有我自己的代码并实现了他的实用程序类:) https://gist.github.com/abdelhady/501f6e48c1f3e32b253a#file-deviceorientation

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM