disabledFlash
public void disableFlashLight() {
if (camera != null) {
Camera.Parameters parameters = camera.getParameters();
parameters.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
camera.setParameters(parameters);
}
}
enableFlash
public void enableFlashLight() {
if (camera != null) {
Camera.Parameters parameters = camera.getParameters();
parameters.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
camera.setParameters(parameters);
}
}
flashLightOff
private void flashLightOff(){
if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH)){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){
CameraManager cameraManager = (CameraManager) Objects.requireNonNull(getActivity()).getSystemService(Context.CAMERA_SERVICE);
try {
String cameraId = cameraManager.getCameraIdList()[0];
cameraManager.setTorchMode(cameraId,false);
} catch (CameraAccessException e) {
e.printStackTrace();
}
}
}else {
Toast.makeText(context, "No Flash Light Available", Toast.LENGTH_SHORT).show();
}
}
flashlight
private void flashLightOn(){
if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH)){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
CameraManager cameraManager = (CameraManager) Objects.requireNonNull(getActivity()).getSystemService(Context.CAMERA_SERVICE);
try {
String cameraID = cameraManager.getCameraIdList()[0];
cameraManager.setTorchMode(cameraID,true);
} catch (CameraAccessException e) {
e.printStackTrace();
}
}
}else {
Toast.makeText(context, "No Flash Light Available", Toast.LENGTH_SHORT).show();
}
}