【问题标题】:Android: get orientation, even if app is locked to portraitAndroid:获取方向,即使应用程序被锁定为纵向
【发布时间】:2018-01-24 19:24:11
【问题描述】:

我正在开发一个在清单文件中锁定为纵向模式的 android camera api 应用程序。

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

我的问题是,当我存储图片时,它们都以相同的方向存储。

我希望它们以真实的方向存储,例如。我的天花板应该在存储图片的顶部,无论我如何定位我的手机,如果这有意义的话

为了做到这一点,我必须知道设备的方向,但是似乎当应用程序被锁定在纵向时,所有 getOrientation'ish 方法都认为我的手机处于纵向模式,无论我的物理方向如何电话。

以下是我尝试过的:

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

getResources().getConfiguration().orientation

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

.

在纵向锁定应用程序中获取真实方向的任何方法?

.

【问题讨论】:

  • 锁定方向会产生问题,就像您遇到的问题一样。正确的解决方案是不锁定方向并处理活动中的方向变化。

标签: java android android-camera android-camera2


【解决方案1】:

简而言之 - 您必须直接使用传感器。 我有点让它工作,但后来我找到了这个人: Android: get device orientation from Azimuth, roll & pitch

所以我基本上删除了我自己的所有代码并实现了他的实用程序类:) https://gist.github.com/abdelhady/501f6e48c1f3e32b253a#file-deviceorientation

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多