Android examples for Camera:Camera Preview
Check if the camera is sideways without taking a picture, but we'll take an educated guess based on whether the camera's preview sizes are mostly the same as our current orientation.
//package com.java2s; import android.app.Activity; import android.hardware.Camera; import android.view.Display; import java.util.List; public class Main { public static boolean getIsCameraSideways( List<Camera.Size> cameraPreviewSizes, Activity activity) { // Get screen dimensions Display display = activity.getWindowManager().getDefaultDisplay(); int width = display.getWidth(); int height = display.getHeight(); boolean isPortrait = (height >= width); int numSidewaysOrientations = 0; for (Camera.Size size : cameraPreviewSizes) { if (isPortrait == (size.height <= size.width)) { numSidewaysOrientations++; }//from w w w .jav a2 s . co m } return (numSidewaysOrientations > cameraPreviewSizes.size() / 2); } }