In Android Lollipop, there was the new Camera2
API, and now, in Android Marshmallow, there are a few more updates to the camera, flashlight, and image reprocessing features.
Almost every device today has a camera, and almost every camera device has a flash unit. The setTorchMode()
method has been added to control the flash torch mode.
The setTorchMode()
method is used in the following manner:
CameraManager.setTorchMode (String cameraId, boolean enabled)
The cameraId
element is the unique ID for the flash unit camera with which you want to change the torch mode. You can use getCameraIdList()
to get the list of cameras and then use getCameraCharacteristics(String cameraId)
to check whether flash is supported in that camera. The setTorchMode()
method allows you to turn it on or off without opening the camera device and without requesting permission from the camera. The torch mode will be switched off as soon as the camera device becomes unavailable or when other...