java Android:获取方向,即使应用程序锁定为纵向
我正在开发一个安卓 camera api应用程序,它在清单文件中锁定为纵向模式
安卓:configChanges="orientation"
安卓:screenOrientation="portrait"
我的问题是,当我存储图片时,它们都以相同的方向存储
我希望它们以真实的方向存储,例如,我的天花板应位于存储图片的顶部,无论我如何定位手机,如果这有意义的话
为了做到这一点,我必须知道设备的方向,但似乎当应用程序锁定在纵向时,所有getOrientation的方法都认为我的手机处于纵向模式,无论我手机的物理方向如何
以下是我尝试过的:
Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
Camera.getCameraInfo(mCurrentlyUsedCamera,cameraInfo);
Log.e("debug","orientation:"+cameraInfo.orientation);
及
getResources().getConfiguration().orientation
及
this.getWindowManager().getDefaultDisplay().getRotation()
# 1 楼答案
简而言之,您必须直接使用传感器。 我有点让它工作了,但后来我发现这个家伙: Android: get device orientation from Azimuth, roll & pitch
因此,我基本上删除了我自己的所有代码,并实现了他的实用程序类:) https://gist.github.com/abdelhady/501f6e48c1f3e32b253a#file-deviceorientation