Cjen1 Cjen1 - 1 year ago 727
Android Question

W/CameraBase﹕ An error occurred while connecting to camera: 0 on camera.open() call

I'm writing a camera app and whenever I call camera.open() the app crashes and then I get this error:

W/CameraBase﹕ An error occurred while connecting to camera: 0

Here is how I'm opening the camera:

public void getCameraInstance(){
mCamera = null;

mCamera = Camera.open(); // attempt to get a Camera instance

catch (Exception e)
// Camera is not available (in use or does not exist)



If you are reading this please note that this is for the original camera API and no longer applies the the latest version of the camera api (camera2).

You should use the camera2 api from this point onwards as it has greater functionality and also has a better image processing pipeline.

Answer Source

To use the following method

android.hardware.Camera.open(int cameraId)

You should pass cameraId, If you want the front camera Id you can use the following method

private int findFrontFacingCamera() {

    // Search for the front facing camera
    int numberOfCameras = Camera.getNumberOfCameras();
    for (int i = 0; i < numberOfCameras; i++) {
        CameraInfo info = new CameraInfo();
        Camera.getCameraInfo(i, info);
        if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
            cameraId = i;
            cameraFront = true;
    return cameraId;
  1. If the same camera is opened by other applications, this will throw a RuntimeException.

  2. You must call release() when you are done using the camera, otherwise it will remain locked and be unavailable to other applications.

  3. Your application should only have one Camera object active at a time for a particular hardware camera.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download