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,
- add check for
camera != null
- only call
camera.setDisplayOrientation(result)
(or perform any heavy-lifting) ifresult
changed since last time the function was called.