So I'm working on an Activity where you're supposed to take a picture and then uploading it to a Parse server.
Everything is working fine except for the flash mode; turning it on works but turning it off doesn't work.
This is my code for turning the flash on:
private void turnOnFlash() {
Camera.Parameters params = camera.getParameters();
if (!isFlashOn) {
if (camera == null || params == null) {
return;
}
params.setFlashMode(Camera.Parameters.FLASH_MODE_ON);
camera.setParameters(params);
isFlashOn = true;
// Show the flash mode in a Toast.
Toast.makeText(this, "Flash mode: " + camera.getParameters().getFlashMode(), Toast.LENGTH_SHORT).show();
// Changing button image.
imgFlash.setImageResource(R.drawable.ic_flash_on_white_48dp);
}
}
This is my code for turning the flash off:
private void turnOffFlash() {
Camera.Parameters params = camera.getParameters();
if (isFlashOn) {
if (camera == null || params == null) {
return;
}
params.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
camera.setParameters(params);
isFlashOn = false;
// Show the flash mode in a Toast.
Toast.makeText(this, "Flash mode: " + camera.getParameters().getFlashMode(), Toast.LENGTH_SHORT).show();
// Changing button image.
imgFlash.setImageResource(R.drawable.ic_flash_off_white_48dp);
}
}
Any help would be appreciated.
EDIT
The Toast that shows the flash mode shows Flash mode: off
when the turnOffFlash()
method is called, but the flash remains on.