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