Android Utililty Methods Camera Get

List of utility methods to do Camera Get

Description

The list of methods to do Camera Get are organized into topic(s).

Method

CameragetDefaultFrontFacingCameraInstance()
get Default Front Facing Camera Instance
return getDefaultCamera(Camera.CameraInfo.CAMERA_FACING_FRONT);
intgetNumberOfCameras()
get Number Of Cameras
return Camera.getNumberOfCameras();
CameragetDefaultBackFacingCameraInstance()
get Default Back Facing Camera Instance
return getDefaultCamera(Camera.CameraInfo.CAMERA_FACING_BACK);
intgetCameraRotation(final Context context)
get Camera Rotation
final WindowManager windowManager = (WindowManager) context
        .getSystemService(Context.WINDOW_SERVICE);
int rotation = windowManager.getDefaultDisplay().getRotation();
final DisplayMetrics metrics = new DisplayMetrics();
windowManager.getDefaultDisplay().getMetrics(metrics);
final int width = metrics.widthPixels;
final int height = metrics.heightPixels;
if ((rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180)
...
IntegerindexOfClosestZoom(Camera.Parameters parameters, double targetZoomRatio)
index Of Closest Zoom
List<Integer> ratios = parameters.getZoomRatios();
Log.i(TAG, "Zoom ratios: " + ratios);
int maxZoom = parameters.getMaxZoom();
if (ratios == null || ratios.isEmpty()
        || ratios.size() != maxZoom + 1) {
    Log.w(TAG, "Invalid zoom ratios!");
    return null;
double target100 = 100.0 * targetZoomRatio;
double smallestDiff = Double.POSITIVE_INFINITY;
int closestIndex = 0;
for (int i = 0; i < ratios.size(); i++) {
    double diff = Math.abs(ratios.get(i) - target100);
    if (diff < smallestDiff) {
        smallestDiff = diff;
        closestIndex = i;
Log.i(TAG, "Chose zoom ratio of "
        + (ratios.get(closestIndex) / 100.0));
return closestIndex;
Camera.SizegetLowestResolution(Camera.Parameters cp)
get Lowest Resolution
List<Camera.Size> sl = cp.getSupportedVideoSizes();
if (sl == null)
    sl = cp.getSupportedPictureSizes();
Camera.Size small = sl.get(0);
for (Camera.Size s : sl) {
    if ((s.height * s.width) < (small.height * small.width))
        small = s;
return small;
voidlaunchCamera(Activity activity)
launch Camera
Intent camera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
camera.putExtra(android.provider.MediaStore.EXTRA_OUTPUT,
        Uri.fromFile(getFileToStoreCameraResult()));
activity.startActivityForResult(camera, CAMERA_RESULT);