I want to implement toggle torch functionality. So that the camera does not get captured and crash - as in Lollipop - I am attempting it with setTorchMode in API 23.
I have a code implementation to turn on or off the torch; however, I don't know how to check the current state of the flash.
CameraManager manager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);
try {
String[] cameras = manager.getCameraIdList();
for (int i = 0; i < cameras.length; i++) {
CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameras[i]);
boolean flashAvailable = characteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE);
if (flashAvailable) {
boolean flashState = getFlashState(); //MISSING METHOD
manager.setTorchMode(cameras[i], !flashState);
}
}
} catch (CameraAccessException e) {
e.printStackTrace();
}
So, how do I implement getFlashState without using the old camera API? And is it possible to do it without capturing the camera?
Aucun commentaire:
Enregistrer un commentaire