Get number Of Cameras vis Reflection - Android android.hardware

Android examples for android.hardware:Camera

Description

Get number Of Cameras vis Reflection

Demo Code

import android.graphics.Bitmap;
import android.hardware.Camera;
import java.lang.reflect.Method;
import java.util.Collections;
import java.util.List;

public class Main{

    public static void main(String[] argv){
        System.out.println(numberOfCameras());
    }/*w  ww . j av a  2 s. co m*/
    /** Returns the number of cameras accessible to the Android API. This is always 1 on platforms earlier than Android 2.3,
     * and on 2.3 or later it is the result of Camera.getNumberOfCameras().
     */
    public static int numberOfCameras() {
        try {
            Method m = Camera.class.getMethod("getNumberOfCameras");
            return ((Number) m.invoke(null)).intValue();
        } catch (Exception ex) {
            return 1;
        }
    }

}

Related Tutorials