Android examples for Camera:Camera Orientation
get Camera Natural Orientation
import android.content.Context; import android.content.res.Configuration; import android.hardware.Camera; import android.util.Log; import android.view.OrientationEventListener; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.List; import java.util.Set; public class Main{ public static int getCameraNaturalOrientation(Context context, int cameraId) { final int deviceNaturalOrientation = DeviceUtil .getDeviceNaturalOrientation(context); if (deviceNaturalOrientation == Configuration.ORIENTATION_UNDEFINED) { return Configuration.ORIENTATION_UNDEFINED; }/* w w w. j a va 2s . c o m*/ final Camera.CameraInfo cameraInfo = getCameraInfo(cameraId); final int relativeCameraOrientation = cameraInfo.orientation; if (deviceNaturalOrientation == Configuration.ORIENTATION_PORTRAIT) { if (relativeCameraOrientation == 0 || relativeCameraOrientation == 180) { return Configuration.ORIENTATION_PORTRAIT; } return Configuration.ORIENTATION_LANDSCAPE; } if (relativeCameraOrientation == 0 || relativeCameraOrientation == 180) { return Configuration.ORIENTATION_LANDSCAPE; } return Configuration.ORIENTATION_PORTRAIT; } public static Camera.CameraInfo getCameraInfo(int cameraId) { Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); Camera.getCameraInfo(cameraId, cameraInfo); return cameraInfo; } }