Android CameraX – manually change exposure compensation?

Tags: , , ,

I’m using CameraX for my project. I have created preview useCase and capture useCase.

final CameraSelector cameraSelector = new CameraSelector.Builder().requireLensFacing(lensFacing).build();

        previewBuilder = new Preview.Builder()

        preview =;

        final ImageCapture.Builder imageCaptureBuilder = new ImageCapture.Builder()

        imageCapture =;

Everything works fine. Now, I need to add functionality to manually change exposure compensation, but I can’t find any reference in official documentation or anywhere else how to do this. Is it possible with CameraX, or I need to switch to Camera2 API?

Please, any help is welcome.


There is new version of CameraX library.

def camerax_version = '1.0.0-beta09'

Firstly add those dependencies to gradle file.

// CameraX core library
implementation "$camerax_version"

// CameraX Camera2 extensions
implementation "$camerax_version"

This version supports Exposure compensation which can be adjusted in runtime. First create preview and takePicure use cases, and then bind those use cases to cameraProvider.

 camera = cameraProvider.bindToLifecycle(this, cameraSelector, preview, imageCapture);

Now we have camera instance and it can be used to retrive CameraInfo, and from CameraInfo, we retrive ExposureState.

ExposureState exposureState = camera.getCameraInfo().getExposureState();

We can use exposureState to check if exposure compensation is supported on device

if (!exposureState.isExposureCompensationSupported()) return;

Next we need to get ExposureCompensation Range

Range<Integer> range = exposureState.getExposureCompensationRange();

Finally, we can set ExposureCompensation index in following way

 if (range.contains(index))

Source: stackoverflow