Samsung Galaxy S5 camera torch not working

We have an application that works with all of our supported Android phones except Samsung Galaxy S5 . Our application uses a camera for shooting at close range. We need a burning mode all the time to focus to take a picture. We check supported parameters and set values, if supported.

Parameters are set, but the event never fires or the camera ignores my settings. I tested with OpenCamera and their application can turn on the torch, but I can’t find the difference between how I set my parameters and how they set them.

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; } 
+1
source share
2 answers

I do it a little differently .. maybe this will help you!

  params = getCamera().getParameters(); ... //Check if device supports torch mode, If YES then enable List<String> supportedFlashModes = params.getSupportedFlashModes(); if (supportedFlashModes != null && supportedFlashModes.contains(Parameters.FLASH_MODE_TORCH)){ params.setFlashMode(Parameters.FLASH_MODE_TORCH); torchModeOn = true; } ... getCamera().setParameters(params); 

In comparison, I use Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE and NOT using setFocusAreas, setMeteringArea, setAutoWhiteBalanceLock, setWhiteBalance or setAutoExposureLock.

After looking at the code, I tried to turn on each of them individually to see if this would affect my photos, and you're out of luck. (My app also requires large-scale snapshots.

Options. FOCUS_MODE_MACRO did not work for me at all on any of the devices with which I tried it.

EDIT:

Here is the order in which I set up the camera if it helps ...

  setCameraDisplayRotation(); params = getCamera().getParameters(); setFocusMode(); //Check if device supports torch mode, If you YES then set on List<String> supportedFlashModes = params.getSupportedFlashModes(); if (supportedFlashModes != null && supportedFlashModes.contains(Parameters.FLASH_MODE_TORCH)){ params.setFlashMode(Parameters.FLASH_MODE_TORCH); torchModeOn = true; } setImageResolution(); getCamera().setParameters(params); // update params before preview.setCamera preview.setCamera(getCamera()); //... some custom code for determining the current screens available space for the preview params.setPreviewSize(size.width, size.height); if(setHiddenParameter(params, "zsl-values", "zsl", "on")){ setUsingZsl(true); }; getCamera().setParameters(params); //update params after preview init 
+1
source

You need to use the new camera2 API in Android Lollipop

Github sample code

and developer's site

+1
source

Source: https://habr.com/ru/post/976618/


All Articles