-1

I'm working on android marshmallow. In my application I'm trying to open android mobile front camera pro grammatically for capturing users profile pic & to display it for preview I've tried lot of examples available that're available in the internet none of the app given perfect out put every example is showing loading of back camera on button click.

Cœur
  • 37,241
  • 25
  • 195
  • 267

1 Answers1

0

You can access Front camera by

Camera.CameraInfo.CAMERA_FACING_FRONT

and here is the example method you can use to access it

private Camera openFrontFacingCameraGingerbread() {
int cameraCount = 0;
Camera cam = null;
Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
cameraCount = Camera.getNumberOfCameras();
for (int camIdx = 0; camIdx < cameraCount; camIdx++) {
    Camera.getCameraInfo(camIdx, cameraInfo);
    if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
        try {
            cam = Camera.open(camIdx);
        } catch (RuntimeException e) {
            Log.e(TAG, "Camera failed to open: " + e.getLocalizedMessage());
        }
    }
}

return cam;
}
Atiq
  • 14,435
  • 6
  • 54
  • 69