You can use an approach like this
private Camera.PictureCallback mPictureCallback = new Camera.PictureCallback() {
@Override
public void onPictureTaken(final byte[] bytes,final Camera camera) {
// Do something here ... save, display ...
}
};
public void takePictureBack(ControllerState state){
Camera camera = null;
int cameraCount = Camera.getNumberOfCameras();
for (int cameraId = 0; cameraId < cameraCount; cameraId++) {
Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
camera = Camera.open(cameraId);
break;
}
}
if (camera!= null) {
Camera.Parameters params = camera.getParameters();
// Check what resolutions are supported by your camera
List<Camera.Size> sizes = params.getSupportedPictureSizes();
// Iterate through all available resolutions and choose one.
for (Camera.Size size : sizes) {
...
}
params.setPictureSize( ... );
camera.setParameters(params);
camera.setPreviewDisplay(mCameraSourcePreview.getSurfaceView().getHolder());
camera.startPreview();
camera.takePicture(null,null,mPictureCallback)
}
}
However be careful since Android does not allow this kind of behaviour when the user is not aware of a picture being taken. The SurfaceView you use for the preview needs to have visibility visible
.
solved take picture automatic , without user interaction in android [closed]