Questions tagged [android-camera]

The Android framework includes support for various cameras and camera features available on devices, allowing you to capture pictures and videos in your applications.

The Android framework includes support for various cameras and camera features available on devices, allowing you to capture pictures and videos in your applications.

Official Android Camera documentation

To access the device camera, you must declare the CAMERA permission in your Android Manifest. Also be sure to include the manifest element to declare camera features used by your application. For example, if you use the camera and auto-focus feature, your Manifest should include the following:

<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />

The Android framework supports capturing images and video through the Camera API or camera Intent.

  • Camera This class is the primary API for controlling device cameras. This class is used to take pictures or videos when you are building a camera application.
  • 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.

The Camera class has been deprecated. It is recommend using the newer class camera2, which works on Android 5.0 (API level 21) or greater.

You can read more about camera2 on Android Official blog. For questions specifically related to camera2, use .

6513 questions
37
votes
11 answers

Android open camera from button

I hope this isn't a duplicate question but I am making an app that I want a button to open the camera app (the default android camera separately). How do I got about doing that? I know there is a…
Ryan Sayles
  • 3,389
  • 11
  • 56
  • 79
37
votes
2 answers

setRotation(90) to take picture in portrait mode does not work on samsung devices

According to the documentation, setRotation(90) should rotate the captured JPEG picture (takePicture in landscape mode. This works fine on a HTC phone, but does not work on Samsung Google Nexus S and Samsung Galaxy S3. Is this a bug? I know that I…
tofi9
  • 5,775
  • 4
  • 29
  • 50
36
votes
10 answers

How does CameraX library can turn ON/OFF the torch?

I am developing a feature with the possibility of switching the torch into ON/OFF states. Some days ago, we saw a new library from Google in io2019. I came up with an idea, why not use it. After some time, I don't see any possibilities to use the…
35
votes
5 answers

How to capture an image and store it with the native Android Camera

I am having a problem capturing an image and storing it from the native camera app. Here is a sample of some of my code. _path = Environment.getExternalStorageDirectory() + "make_machine_example.jpg"; File file = new File( _path ); Uri…
35
votes
1 answer

Media Recorder with Google Vision API

I am using the FaceTracker sample from the Android vision API. However, I am experiencing difficulty in recording videos while the overlays are drawn on them. One way is to store bitmaps as images and process them using FFmpeg or Xuggler to merge…
35
votes
4 answers

Activity killed / onCreate called after taking picture via intent

I am trying to take a picture using an intent. My problem is that sometimes after taking a picture my activity, which calls startActivityForResult, seems to be destroyed so that onCreate is called again. Here is my code for taking pictures after…
33
votes
2 answers

Camera display / preview in full screen does not maintain aspect ratio - image is skewed, stretched in order to fit on the screen

I have developed a small application for displaying camera preview in full screen. I'm using Camera API for this. This is the activity layout:
Paul
  • 3,812
  • 10
  • 50
  • 73
33
votes
5 answers

Upload an Image from camera or gallery in WebView

WebView in this app opens a page with upload button. Below is the code block that allows to open a dialog box to upload image from gallery or camera. Within my Activity I have: private WebView wv; //make HTML upload button work in Webview …
32
votes
6 answers

Convert bitmap array to YUV (YCbCr NV21)

How to convert Bitmap returned by BitmapFactory.decodeFile() to YUV format (simillar to what camera's onPreviewFrame() returns in byte array)?
Abhijeet Pathak
  • 1,948
  • 3
  • 20
  • 28
32
votes
4 answers

What is the Camera2 API Equivalent of setDisplayOrientation()?

With android.hardware.Camera, in order to have the camera output appropriately track the device movement, we need to hook up an OrientationEventListener to the setDisplayOrientation() method on Camera. That way, as the user twists the device around,…
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
31
votes
6 answers

Extract black and white image from android camera's NV21 format

I have done some google-ing around and couldn't find enough information about this format. It is the default format for camera preview. Can anyone suggest good sources of information about it and how to extract data from a photo/preview image with…
Ethan
  • 1,488
  • 3
  • 19
  • 24
31
votes
6 answers

Access denied finding property "camera.hal1.packagelist"

While using camera in service mobile screen is getting un-touchable(locked by transparent window ) and only below error is occuring Access denied finding property "camera.hal1.packagelist" what will be the reason and its solution? Please help..
Amin Pinjari
  • 2,129
  • 3
  • 25
  • 53
31
votes
5 answers

Take picture and convert to Base64

I use code below to make a picture with camera. Instead of saving I would like to encode it to Base64 and after that pass it to another API as an input. I can't see method, how to modify code to take pictures in Base64 instead of regular…
plaidshirt
  • 5,189
  • 19
  • 91
  • 181
31
votes
7 answers

Unfortunately, Camera has stopped

When I launch the Camera application I am getting this error, and this is my logcat. 12-08 12:50:10.393 2275-2369/com.android.launcher3 E/Surface: getSlotFromBufferLocked: unknown buffer: 0xa21675b0 12-08 12:50:10.509 965-3048/?…
31
votes
1 answer

Reading RGB images with an ImageReader

I'm trying to use an ImageReader to get RGB images from the camera. I'm using the Camera2 API from Android 5.0 "L" on a Nexus 5 running the developer preview. Note that I am not asking how to convert YUV into RGB - I'm trying to get RGB directly…
nneonneo
  • 171,345
  • 36
  • 312
  • 383