I have a custom camera application. When I rotating the phone by 90, camera preview works fine. But when I rotate phone quickly 180 degree, camera preview turns upside down.
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,
camera != null
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.