We have an app that works with all our supported Android phones "except Samsung Galaxy S5". Our app uses the camera to take pictures at close range. We need torch mode ON the entire time we are focusing to take the picture. We check for supported parameters and set the values if supported.
The params get set but the event either never gets fired or the camera is ignoring my settings. I tested using OpenCamera and their app is able to turn the torch on yet I cannot find the difference between how I set my params vs. how they set theirs.
Here is our code:
//Set all camera parameters(flash, focus, white balance, etc)
private void setCameraParameters()
{
//Rotate the orientation of the preview to match orientation of device
camera.setDisplayOrientation(getCameraRotation());
//A Parameters object must be used to set the other parameters.
Parameters params = camera.getParameters();
//Flash Mode to Torch if supported
if(params.getSupportedFlashModes().contains("torch"))
{
// Torch mode
params.setFlashMode(Parameters.FLASH_MODE_TORCH);
}
//Focus Mode to Macro if supported, Auto if not
if(params.getSupportedFocusModes().contains("macro"))
{
//Macro focus mode
params.setFocusMode(Parameters.FOCUS_MODE_MACRO);
}
else
{
//Auto focus mode
params.setFocusMode(Parameters.FOCUS_MODE_AUTO);
}
//White Balance mode to Auto if available.
List<String> supported_white = params.getSupportedWhiteBalance();
if(supported_white!=null)
{
if(supported_white.contains("auto"))
{
params.setWhiteBalance(Parameters.WHITE_BALANCE_AUTO);
}
}
// Auto Exposure Lock to false if available
if(params.isAutoExposureLockSupported())
{
params.setAutoExposureLock(false);
}
// Auto White Balance Lock if available.
if(params.getAutoWhiteBalanceLock())
{
params.setAutoWhiteBalanceLock(false);
}
//JPEG quality set to 100(highest)
{
params.setJpegQuality(100);
}
//Set focus area and metering area
List<Camera.Area> focusArea = calculateFocusArea();
params.setFocusAreas(focusArea);
params.setMeteringAreas(focusArea);
Camera.Size size = pickCameraSize(params.getSupportedPictureSizes());
params.setPictureSize(size.width, size.height);
//Set new parameters for camera
camera.setParameters(params);
boolean torch = getTorchState(camera);
}
// Added this method from zxing github to see if the value is being set
boolean getTorchState(Camera camera) {
if (camera != null) {
Camera.Parameters parameters = camera.getParameters();
if (parameters != null) {
String flashMode = camera.getParameters().getFlashMode();
return flashMode != null
&& (Camera.Parameters.FLASH_MODE_ON.equals(flashMode) || Camera.Parameters.FLASH_MODE_TORCH
.equals(flashMode));
}
}
return false;
}