Search Results for

    Show / Hide Table of Contents

    Work With Android Camera2 API

    Camera2 API in Android allows you to access certain features of the phone's camera via the software, such as auto-focus, RAW Capture, control of lens and flash, etc.

    To use the Android Camera2 API, you should first use the Camera2SourceListener or the Camera2Source class to get access to Android's Camera2 CaptureRequest.Builder and CameraCaptureSession classes for the session, and then update the CaptureRequest and apply the desired changes.

    The following example shows how to update the flash mode.

    First, get access to the Camera2 API:

    @Override
        protected VideoSource createVideoSource() {
            source = new Camera2Source(viewSink, videoConfig);
            Camera2SourceListener listener = new Camera2SourceListener() {
                @Override
                public void onCameraCaptureSession(CameraCaptureSession cameraCaptureSession) {
                    session = cameraCaptureSession;
                }            
                @Override
                public void onCameraRequestBuilder(CaptureRequest.Builder builder) {
                    reqBuilder = builder;
                }
            };
            source.setListener(listener);        
            return source;
        }
    

    Then, set the flash mode parameters and apply updates to the session:

    reqBuilder.set(CaptureRequest.FLASH_MODE, CaptureRequest.FLASH_MODE_TORCH);
    session.setRepeatingRequest(reqBuilder.build(), null, null);
    
    In This Article
    Back to top Copyright © LiveSwitch Inc. All Rights Reserved.Documentation for LiveSwitch Version 1.24.5