0

I am scanning barcode in android using camera. But there is requirement to switch on the flash light automatically if there is dark area while scanning the barcode and after reading the barcode, will turn it off. I want it in same way as android default camera app does.

For this I also tried with Light sensor but it is not best suitable for my app.

Bajrang Hudda
  • 3,028
  • 1
  • 36
  • 63

2 Answers2

1

you can use FLASH_MODE_AUTO of the Camera.Parameters class

you can do something like

Camera cam = Camera.open();     
Parameters p = cam.getParameters();
p.setFlashMode(Parameters.FLASH_MODE_AUTO);
cam.setParameters(p);
cam.startPreview();

Also make sure phone has flash feature

you can check with

context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);

and don't forget to add permission

android.permission.FLASHLIGHT
Pooja_So
  • 19
  • 3
0

You can't detect any darkness or light in environment without using LightSensor, but if you still want to detect you can find pixel intensity of the captured image or preview frame. This link for sure help you to do this.. [How to detect average pixel intensity from live camera preview?

Community
  • 1
  • 1
Bajrang Hudda
  • 3,028
  • 1
  • 36
  • 63