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.