The Android Developer Challenge is back! Submit your idea before December 2.

Image capture

The image capture use case is designed for capturing high-resolution, high-quality photos and provides auto-white-balance, auto-exposure, and auto-focus (3A) functionality, in additional to simple manual camera controls. The caller is responsible for deciding how to use the captured picture, including the following options:

  • takePicture(OnImageCapturedListener): This method provides an in-memory buffer of the captured image.
  • takePicture(File, OnImageSavedListener): This method saves the captured image to the provided file location.
  • takePicture(File, OnImageSavedListener, Metadata): This method enables you to specify the metadata to embed in the saved file's Exif.


Basic controls for taking pictures are provided. Pictures are taken with flash options and using continuous auto-focus.

To optimize photo capture for latency, set ImageCapture.CaptureMode to MIN_LATENCY. To optimize for quality, set it to MAX_QUALITY.

The following code sample shows how to configure your app to take a photo:


val imageCaptureConfig = ImageCaptureConfig.Builder()

val imageCapture = ImageCapture(imageCaptureConfig)

CameraX.bindToLifecycle(this as LifecycleOwner,
    imageCapture, imageAnalysis, preview)


ImageCaptureConfig config =
    new ImageCaptureConfig.Builder()

ImagesCapture imageCapture = new ImageCapture(config);

CameraX.bindToLifecycle((LifecycleOwner) this, imageCapture, imageAnalysis, preview);

Once you've configured the camera, the following code takes a photo based on user action:


fun onClick() {
    val file = File(...)
        object : ImageCapture.OnImageSavedListener {
            override fun onError(error: ImageCapture.ImageCaptureError,
                                 message: String, exc: Throwable?) {
                // insert your code here.
            override fun onImageSaved(file: File) {
                // insert your code here.


public void onClick() {
    File file = new File(...);

        new ImageCapture.OnImageSavedListener() {
            public void onImageSaved(File file) {
                // insert your code here.
            public void onError(
                    ImageCapture.ImageCaptureError imageCaptureError,
                    String message,
                    Throwable cause) {
                // insert your code here.

The image capture method fully supports the JPEG format.

Additional resources

To learn more about CameraX, consult the following additional resources.


  • Getting Started with CameraX
  • Code sample

  • Official CameraX sample app