Camera API

The Android framework includes support for various cameras and camera features available on devices, allowing you to capture pictures and videos in your applications. This document discusses a quick, simple approach to image and video capture and outlines an advanced approach for creating custom camera experiences for your users.

Note: This page describes the Camera class, which has been deprecated. We recommend using the CameraX Jetpack library or, for specific use cases, the camera2, class. Both CameraX and Camera2 work on Android 5.0 (API level 21) and higher.

Refer to the following related resources:

Considerations

Before enabling your application to use cameras on Android devices, you should consider a few questions about how your app intends to use this hardware feature.

  • Camera Requirement - Is the use of a camera so important to your application that you do not want your application installed on a device that does not have a camera? If so, you should declare the camera requirement in your manifest.
  • Quick Picture or Customized Camera - How will your application use the camera? Are you just interested in snapping a quick picture or video clip, or will your application provide a new way to use cameras? For getting a quick snap or clip, consider Using Existing Camera Apps. For developing a customized camera feature, check out the Building a Camera App section.
  • Foreground Services Requirement - When does your app interact with the camera? On Android 9 (API level 28) and later, apps running in the background cannot access the camera. Therefore, you should use the camera either when your app is in the foreground or as part of a foreground service.
  • Storage - Are the images or videos your application generates intended to be only visible to your application or shared so that other applications such as Gallery or other media and social apps can use them? Do you want the pictures and videos to be available even if your application is uninstalled? Check out the Saving Media Files section to see how to implement these options.

The basics

The Android framework supports capturing images and video through the android.hardware.camera2 API or camera Intent. Here are the relevant classes:

android.hardware.camera2
This package is the primary API for controlling device cameras. It can be used to take pictures or videos when you are building a camera application.
Camera
This class is the older deprecated API for controlling device cameras.
SurfaceView
This class is used to present a live camera preview to the user.
MediaRecorder
This class is used to record video from the camera.
Intent
An intent action type of MediaStore.ACTION_IMAGE_CAPTURE or MediaStore.ACTION_VIDEO_CAPTURE can be used to capture images or videos without directly using the Camera object.

Manifest declarations

Before starting development on your application with the Camera API, you should make sure your manifest has the appropriate declarations to allow use of camera hardware and other related features.

  • Camera Permission - Your application must request permission to use a device camera.
    <uses-permission android:name="android.permission.CAMERA" />

    Note: If you are using the camera by invoking an existing camera app, your application does not need to request this permission.

  • Camera Features - Your application must also declare use of camera features, for example:
    <uses-feature android:name="android.hardware.camera" />

    For a list of camera features, see the manifest Features Reference.

    Adding camera features to your manifest causes Google Play to prevent your application from being installed to devices that do not include a camera or do not support the camera features you specify. For more information about using feature-based filtering with Google Play, see Google Play and Feature-Based Filtering.

    If your application can use a camera or camera feature for proper operation, but does not require it, you should specify this in the manifest by including the android:required attribute, and setting it to false:

    <uses-feature android:name="android.hardware.camera" android:required="false" />
  • Storage Permission - Your application can save images or videos to the device's external storage (SD Card) if it targets Android 10 (API level 29) or lower and specifies the following in the manifest.
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  • Audio Recording Permission - For recording audio with video capture, your application must request the audio capture permission.
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
  • Location Permission - If your application tags images with GPS location information, you must request the ACCESS_FINE_LOCATION permission. Note that, if your app targets Android 5.0 (API level 21) or higher, you also need to declare that your app uses the device's GPS:

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    ...
    <!-- Needed only if your app targets Android 5.0 (API level 21) or higher. -->
    <uses-feature android:name="android.hardware.location.gps" />

    For more information about getting user location, see