I got a strange situation.

I work with the example of Google camera2API and I need to make the flash work every time the user takes a photo.

For this, I changed one line in the method

 private void setAutoFlash(CaptureRequest.Builder requestBuilder) { if (mFlashSupported) { // requestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH); requestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON_ALWAYS_FLASH); } } 

I changed CONTROL_AE_MODE_ON_AUTO_FLASH to CONTROL_AE_MODE_ON_ALWAYS_FLASH.

I am testing the code on three Meizu MX5 , Samsung S5 and Samsung S6 So that's what happened, now the Meizu MX5 and Samsung S5 work as expected and the flash fires with each photo.

But for Samsung S6 this approach does not work, and when the user clicks on the Make photo button, the flash fires and that's it ... The application hangs ...

What I found out: the setAutoFlash() method is called in the code in three different methods

  1. captureStillPicture()
  2. unlockFocus()
  3. onConfigured()

So if in the captureStillPicture() method captureStillPicture() block the call to the setAutoFlash() method, then the application works correctly for the Samsung S6 , but then the flash does not work on the Meizu MX5 and Samsung S5 .

What am I doing wrong?

    1 answer 1

    In the end I found a solution.

    As I said, the setAutoFlash() method is called in three different places in the code.

    This method accepts the CaptureRequest.Builder requestBuilder as an CaptureRequest.Builder requestBuilder so if for each build that causes this method to set the same parameter for the flash, the application freezes.

    I took it locally in each method that caused this method to implement the settings for the flash, like this:

    1. unlockFocus() -> mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON_ALWAYS_FLASH);
    2. onConfigured() -> mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON_ALWAYS_FLASH);

    and left auto settings for this method

    1. captureStillPicture() -> captureBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH);

    and now everything works for all devices.

    But if someone knows why this happens, please write a reason in the comments.