Rotating phone quickly 180 degrees, camera preview turns upside down

最后都变了- 提交于 2019-11-26 19:05:34

You can use OrientationEventListener to trigger recalculation of camera rotation.

Add to your activity:

private OrientationEventListener orientationListener = null;

to onCreate():

orientationListener = new OrientationEventListener(this) {
    public void onOrientationChanged(int orientation) {
        setCameraDisplayOrientation(CustomCameraActivity.this, cameraId, camera);
    }
};

to surfaceCreated():

orientationListener.enable();

to surfaceDestroyed():

orientationListener.disable();

Now, it almost works. To make setCameraDisplayOrientation() more robust,

  1. add check for camera != null
  2. only call camera.setDisplayOrientation(result) (or perform any heavy-lifting) if result changed since last time the function was called.

android:configChanges="keyboardHidden|orientation|screenSize"

Add this line in your Android Manifest file after declaring all activities in activity tags *

like:

<activity android:name="com.geeklabs.ActivityMain"
            android:configChanges="keyboardHidden|orientation|screenSize" />

May be it will helps you.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!