Set the flash type of the camera instance - Android Camera

Android examples for Camera:Camera Flash

Description

Set the flash type of the camera instance

Demo Code


//package com.java2s;

import android.hardware.Camera;

public class Main {
    public static final String FLASH_ON = "FLASH_ON";
    public static final String FLASH_AUTO = "FLASH_AUTO";
    public static final String FLASH_OFF = "FLASH_OFF";

    /**/*w  w  w  . j a  v  a 2  s  .co  m*/
     * Set the flash type of the camera instance
     * @param   camera  The camera instance
     * @param   cameraFlashType The flash type
     */
    public static void setCameraFlashType(Camera camera,
            String cameraFlashType) {
        if (cameraFlashType.equals(FLASH_ON)) {
            Camera.Parameters param = camera.getParameters();
            param.setFlashMode(Camera.Parameters.FLASH_MODE_ON);
            camera.setParameters(param);
        } else if (cameraFlashType.equals(FLASH_OFF)) {
            Camera.Parameters param = camera.getParameters();
            param.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
            camera.setParameters(param);
        } else if (cameraFlashType.equals(FLASH_AUTO)) {
            Camera.Parameters param = camera.getParameters();
            param.setFlashMode(Camera.Parameters.FLASH_MODE_AUTO);
            camera.setParameters(param);
        }
    }
}

Related Tutorials