take Picture via android.hardware.Camera - Android android.hardware

Android examples for android.hardware:Camera

Description

take Picture via android.hardware.Camera

Demo Code

import android.hardware.Camera;
import android.hardware.Camera.CameraInfo;

public class Main {
  public static void takePicture() {
    Camera camera;/*from  w ww  .j a  v  a2s .c  om*/
    int cameraId = -1;
    int numberOfCameras = Camera.getNumberOfCameras();
    for (int i = 0; i < numberOfCameras; i++) {
      CameraInfo info = new CameraInfo();
      Camera.getCameraInfo(i, info);
      if (info.facing == CameraInfo.CAMERA_FACING_BACK) {
        cameraId = i;
        break;
      }
    }
    if (cameraId >= 0) {
      camera = Camera.open(cameraId);
      camera.release();
    }
  }
}

Related Tutorials