I am trying to turn the flashlight on as the camera starts but here is what is actually happening. My flashlight turns on and then its goes off after a couple of milliseconds. I am really confused as what is causing that to happen. I am using the camera2 api and I am targeting devices with api >21 This is what I tried so far.
Asked
Active
Viewed 199 times
0
-
Does the app works if you don't turn the light on? It seems you've forgotten to ask to the user the permission to use the camera. – Eselfar Dec 11 '17 at 12:50
-
@Eselfar:- Yes the app works fine and the camera starts fine and works properly. The only problem is that the flash light doesnt stay on. It just blinks when the app starts and then thats it. – Monica Das Dec 11 '17 at 12:54
-
check it out:- https://stackoverflow.com/questions/27420594/android-5-camera2-use-only-flash , https://stackoverflow.com/questions/6068803/how-to-turn-on-camera-flash-light-programmatically-in-android – InsaneCat Dec 11 '17 at 13:07
1 Answers
0
@InsaneCat is right (see this link)
Remove your calls to turnOnFlashLight
and do:
In protected void createCameraPreview()
...
Surface surface = new Surface(texture);
captureRequestBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
// Add this line:
captureRequestBuilder.set(CaptureRequest.FLASH_MODE, CameraMetadata.FLASH_MODE_TORCH);
captureRequestBuilder.addTarget(surface);
...

Eselfar
- 3,759
- 3
- 23
- 43