get Camera First Id - Android Camera

Android examples for Camera:Camera Attribute

Description

get Camera First Id

Demo Code


//package com.java2s;

import android.content.Context;

import android.hardware.Camera;

public class Main {
    private static int sCameraFirstIndex = -1;

    public static int getCameraFirstId(Context ctx) {

        if (sCameraFirstIndex != -1)
            return sCameraFirstIndex;

        Camera camera = null;/*from  w  w  w  . j a v a  2 s .  co m*/

        try {
            camera = Camera.open(0);
            sCameraFirstIndex = 0;
            camera.release();
            camera = null;

        } catch (Exception ex) {
            sCameraFirstIndex = 1;
        }

        return sCameraFirstIndex;
    }
}

Related Tutorials