Why does flash drives app in stack? CONTROL_AE_MOD

2019-09-20 17:35发布

问题:

There is weird situation. I took standard google sample camera2API.

I need that flash is worked permanently, regardless of outside light.

In order to accomplish it i have changed one line of code:

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);
    }
}

It was CONTROL_AE_MODE_ON_AUTO_FLASH i have changed it to CONTROL_AE_MODE_ON_ALWAYS_FLASH.

And i have faced with issue, when i click Take picture button, camera is flashing and that is it. App goes to stack...

What am i doing wrong?

EDIT

I figure out next:

i have tryed tern on flash on three different device Meizu MX5, Samsung S5 and Samsung S6.

Two of them Meizu MX5, Samsung S5 work correctly with code above and app doesn't drives in stack.

Problem occur with Samsung S6, BUT ...

Method setAutoFlash() invokes within code 3 times in different places

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

And trick is if i disable setAutoFlash() in captureStillPicture() for Samsung S6 it is stop stacking and flash begins to works but if i try this approach for Meizu MX5, Samsung S5 flash doesn't works...

回答1:

Eventually i found solution

As i said method

protected final void setAutoFlash(CaptureRequest.Builder requestBuilder) {
    if (isFlashSupported) {
        requestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH);
    }
}

invoked in three different places in code.

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

So i implemented this line requestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH); locally in each method.

Finally that i get :

  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 for this method remained auto settings

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

But i don't know the reason why i got such issue... If someone know the reason please let me know.