In one of the requirement in my app I need to pop up an activity containing the front camera preview,at this same time I need to turn on the flashlight as well.However I obs
The following code checks for the availability of a front camera:
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;
}
Then add the following permissions in the AndroidManifest.xml file:
Note: This feature is available in Gingerbread(2.3) and Up Android Version.
I recommend using surfaceView like in this example to implement a working flashlight.
Hope this helps :)