Skip to content

Commit 0738efc

Browse files
committed
catch camera light error on moto g7 plus
1 parent e0204de commit 0738efc

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

ui/src/main/java/io/snabble/sdk/ui/scanner/BarcodeScannerView.java

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -457,25 +457,27 @@ public void run() {
457457
*/
458458
public void setTorchEnabled(boolean enabled) {
459459
if (camera != null && running) {
460-
Camera.Parameters parameters = camera.getParameters();
461-
if (parameters != null) {
462-
List<String> supportedFlashModes = parameters.getSupportedFlashModes();
463-
if (supportedFlashModes != null
464-
&& supportedFlashModes.contains(Camera.Parameters.FLASH_MODE_TORCH)
465-
&& supportedFlashModes.contains(Camera.Parameters.FLASH_MODE_OFF)) {
466-
if (enabled) {
467-
parameters.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
468-
} else {
469-
parameters.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
460+
try {
461+
Camera.Parameters parameters = camera.getParameters();
462+
463+
if (parameters != null) {
464+
List<String> supportedFlashModes = parameters.getSupportedFlashModes();
465+
if (supportedFlashModes != null
466+
&& supportedFlashModes.contains(Camera.Parameters.FLASH_MODE_TORCH)
467+
&& supportedFlashModes.contains(Camera.Parameters.FLASH_MODE_OFF)) {
468+
if (enabled) {
469+
parameters.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
470+
} else {
471+
parameters.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
472+
}
470473
}
471-
}
472474

473-
try {
474475
camera.setParameters(parameters);
475476
torchEnabled = enabled;
476-
} catch (RuntimeException e) {
477-
// this is terrible, but happens on some devices in rare circumstances
478477
}
478+
} catch (RuntimeException e) {
479+
// this is terrible, but happens on some devices in rare circumstances
480+
// one confirmed device is the motorola moto g7 plus
479481
}
480482
}
481483
}

0 commit comments

Comments
 (0)