3
votes

I am trying to capture a picture using the android Camera2 Api. Everything is working quite well. However, there is a problem that I am facing. So, when my app loads up, the torch is turned on during the preview session. But my goal is when I take the photo, the torch doesn't go off. Right now, when I take a photo , it switches to flash mode and then back to torch mode. I don't want it to flash and rather the torch stays on during the camera capture. How do I go about it?

 mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE,                                
                             CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
 if(autoflashstate==0){
    //turn on torch                                       
    mPreviewRequestBuilder.set(CaptureRequest.FLASH_MODE, 
                                CameraMetadata.FLASH_MODE_TORCH);                                     
    mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_REGIONS, 
                                new MeteringRectangle[]{focusAreaTouch});                                        
    mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_REGIONS, 
                                new MeteringRectangle[]{insideFocusAreaTouch});    
 }

 /*  else{
     //turn off flash light and then turn on torch
     unlockAutoFlash(mPreviewRequestBuilder);
                                    
     mPreviewRequestBuilder.set(CaptureRequest.FLASH_MODE, CameraMetadata.FLASH_MODE_TORCH);
                                    
     mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_REGIONS, new MeteringRectangle[]{focusAreaTouch});
                                    
     mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_REGIONS, new MeteringRectangle[]{insideFocusAreaTouch});
        
    
 }*/
2
Monica Das have you solved this issue? - sgallego

2 Answers

4
votes

Do you set the FLASH_MODE to TORCH in your still capture request as well?

Also make sure your AE_MODE is just ON, not ON_AUTO_FLASH or ON_ALWAYS_FLASH, since those override the FLASH_MODE setting.

-1
votes

I solved this problem, you need not only set the flash mode of the previewsurface, but also the capture session flash mode.

//first preview 
            mPreviewRequestBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
            mPreviewRequestBuilder.addTarget(previewSurface);

setFlashMode(mPreviewRequestBuilder)
//second when u take pickture
            final CaptureRequest.Builder captureBuilder =
                mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
            captureBuilder.addTarget(mImageReader.getSurface());
setFlashMode(captureBuilder)