Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if the device has front and rear facing cameras?

I need to detect if the phone has a front facing camera, and if so, I need to calculate the megapixels. The same thing goes for a rear facing camera.

I know how to get the megapixels of a "Camera" object, but I don't know how to check for the other things.

P.s.: I would also be nice if you know a way to check if the Camera has flash or not, and other cool statistics about the camera

like image 464
Pableras84 Avatar asked Jan 27 '13 12:01

Pableras84


2 Answers

I always try to create helpers check if you have a front Camera:

public static boolean checkCameraFront(Context context) {
    if(context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FRONT)) {
        return true;
    } else {
        return false;
    }
}

Check if you have Camera in your device

public static boolean checkCameraRear() {
    int numCamera = Camera.getNumberOfCameras();
    if(numCamera > 0) {
        return true;
    } else {
        return false;
    }
}
like image 139
Ezequiel García Avatar answered Sep 28 '22 23:09

Ezequiel García


http://developer.android.com/reference/android/hardware/Camera.html#getNumberOfCameras() , introduced in API lvl 9. This gets you the number of cameras

http://developer.android.com/reference/android/hardware/Camera.CameraInfo.html contains information of its facing direction.

http://developer.android.com/reference/android/hardware/Camera.Parameters.html#getPictureSize() is megapixels, if counted

http://developer.android.com/reference/android/hardware/Camera.Parameters.html#getFlashMode() returns null if no flash..

many other parameters can be gotten from the camera object too

http://developer.android.com/reference/android/hardware/Camera.html has step by step instructions for using camera. You can follow these instructions if you understand any object oriented language.

like image 23
Gjordis Avatar answered Sep 28 '22 21:09

Gjordis