Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android : How to turn flashlight on/off programmly using Camera Source Builder?

i made Camera Preview using CameraSource in Android Studio

new CameraSource.Builder(this , detector).setAutoFocusEnabled(true).build();

as you can see i easliy set the Auto Focus Enabled.

i was just wondering if there is an easy way to enable/disable flashlight ?

like image 798
Fadi A. Avatar asked Sep 19 '26 08:09

Fadi A.


1 Answers

Just use this method:

.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH).build();

Edit:

This class was deprecated in API level 21. Google recommends using the new android.hardware.camera2 API for new applications.

In this thread you can see how to use: Turning on/off flash with Android camera2 API not working

like image 197
Issamu Avatar answered Sep 20 '26 22:09

Issamu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!