set Camera Flash Type - Android android.hardware

Android examples for android.hardware:Flash

Description

set Camera Flash Type

Demo Code

import android.hardware.Camera;

public class Main {

  public static final String FLASH_AUTO = "FLASH_AUTO";
  public static final String FLASH_OFF = "FLASH_OFF";
  public static final String FLASH_ON = "FLASH_ON";

  /**/*from  w  ww .j a v a2 s.c  o 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