is back Camera Available - Android Camera

Android examples for Camera:Back Camera

Description

is back Camera Available

Demo Code


//package com.java2s;
import android.hardware.Camera;
import android.hardware.Camera.CameraInfo;

public class Main {
    private static Boolean available;

    static public boolean isAvailable() {
        if (available == null) {
            try {
                getBackId();/*  www. jav a2  s.c o  m*/
                available = true;
            } catch (Exception e) {
                available = false;
            }
        }
        return available;
    }

    static public int getBackId() throws Exception {
        int numberOfCameras = Camera.getNumberOfCameras();
        CameraInfo cameraInfo = new CameraInfo();
        for (int i = 0; i < numberOfCameras; i++) {
            Camera.getCameraInfo(i, cameraInfo);
            if (cameraInfo.facing == CameraInfo.CAMERA_FACING_BACK) {
                return i;
            }
        }
        throw new Exception();
    }
}

Related Tutorials