Change Android flashlight brightness

778 Views Asked by At

I'm looking for something like this:

CameraManager cameraManager = (CameraManager) getSystemService(CAMERA_SERVICE);
cameraManager.setTorchMode("0", true);
cameraManager.setTorchLevel("0", 2); //change the brightness based on the number given
2

There are 2 best solutions below

0
Daniel Martinek On

This will work only on devices with android 13 and new version of camera hardware abstraction layer (tested on pixel 6 pro). It might also work on some samsung devices with lower android version (not tested).

0
Sai Ganesh On

Try this CameraManager API:

public void Turnontorch() throws CameraAccessException { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { camManager.turnOnTorchWithStrengthLevel(cameraId,TorchStrength); }

The range of TorchStrength can be from 1 to CameraCharacteristics.FLASH_INFO_STRENGTH_MAXIMUM_LEVEL.

For more details, refer Control the Strength of Torch(only for Android 13 or higher)