How to capture a photo from the camera without intent

capture multiple images from camera android
android capture image from camera and display in another activity
take photo from camera and gallery in android example
android camera intent high resolution
how to open camera in android programmatically
android camera tutorial
access camera without permission android
android take picture from front camera programmatically

I want my app to be able to capture photos without using another application. The code i used :

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    File photo = null;
        photo = this.createTemporaryFile("picture", ".jpg");
    catch(Exception e)

    mImageUri = Uri.fromFile(photo);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, mImageUri);
    startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);

But this code uses the phone's main camera app. Can anyone give me some code ?

Taking a picture directly using the Camera class is insanely complicated to get right.

I am working on a library to simplify this, where you just add a CameraFragment to your app for the basic preview UI, and call takePicture() on it to take a picture, with various ways to configure the behavior (e.g., where the pictures get saved). However, this library is still a work in progress.

Can anyone give me some code ?

"Some code" is going to be thousands of lines long (for a complete implementation, including dealing with various device-specific oddities).

You are welcome to read the Android developer documentation on the subject.

How to take a picture without an Intent and without any view window , context = context; } public void onPictureTaken(byte[] data, Camera camera) { File pictureFileDir = getDir(); if (!pictureFileDir.exists() && !pictureFileDir. The Android Camera application saves a full-size photo if you give it a file to save into. You must provide a fully qualified file name where the camera app should save the photo. Generally, any photos that the user captures with the device camera should be saved on the device in the public external storage so they are accessible by all apps.

once you have the camera preview set, you need to do the following...

protected static final int MEDIA_TYPE_IMAGE = 0; 

public void capture(View v)
    PictureCallback pictureCB = new PictureCallback() {
        public void onPictureTaken(byte[] data, Camera cam) {
          File picFile = getOutputMediaFile(MEDIA_TYPE_IMAGE);
          if (picFile == null) {
            Log.e(TAG, "Couldn't create media file; check storage permissions?");

          try {
            FileOutputStream fos = new FileOutputStream(picFile);
          } catch (FileNotFoundException e) {
            Log.e(TAG, "File not found: " + e.getMessage());
          } catch (IOException e) {
            Log.e(TAG, "I/O error writing file: " + e.getMessage());
      camera.takePicture(null, null, pictureCB);

And the getOutputMediaFile function:

private File getOutputMediaFile(int type) 
      File dir = new File(Environment.getExternalStoragePublicDirectory(
                    Environment.DIRECTORY_PICTURES), getPackageName());
      if (!dir.exists()) 
        if (!dir.mkdirs()) 
          Log.e(TAG, "Failed to create storage directory.");
          return null;
      String timeStamp = new SimpleDateFormat("yyyMMdd_HHmmss", Locale.UK).format(new Date());
      if (type == MEDIA_TYPE_IMAGE) 
        return new File(dir.getPath() + File.separator + "IMG_"+ timeStamp + ".jpg");
        return null;

And you are done!!!

found it here

Take photos, This lesson explains how to capture photos using an existing camera because if you call startActivityForResult() using an intent that no app  When the app is opened, it displays the “Camera” Button to open the camera. When pressed, ACTION_IMAGE_CAPTURE Intent gets started by the MediaStore class. When the image is captured, it is displayed in the imageview. How to create an App to open Camera through Intent and display captured image. Step1: Firstly create a new Android

Camera was deprecated in API 21, the new way is the use android.hardware.camera2.

To enumerate, query, and open available camera devices, obtain a CameraManager instance.

To quickly summarize:

  1. Obtain a camera manager instance by calling Context.getSystemService(String)
  2. Get a string[] of device camera IDs by calling CameraManager.GetCameraIdList().
  3. Call CameraManager.OpenCamera(...) with the desired camera ID from the previous step.

Once the camera is opened, the callback provided in OpenCamera(...) will be called.

Android's New Image Capture from a Camera using File Provider, If you want to handle, what if the user cancelled the camera intent without taking a picture like, though we have the imagePath, but it's not a  In this post, we’re going to learn how we can access the camera and use it to take a picture. Grabbing data from the camera can be a bit tricky, especially when dealing with the Android filesystem so we’ll be covering how to create an image file for the photo and extracting that image back into the ImageView.

Taking Photos Simply, In doing so, Google Play will allow devices without a camera to download your application. It's then  Many Android devices are equipped with at least one camera. There are a number of ways to allow the user to record video from within an Android application via these built-in cameras, but by far the easiest approach is to make use of a camera intent included with the Android operating system.

Accessing the Camera and Stored Media, The easy way - launch the camera with an intent, designating a file path, and fileProvider); // If you call startActivityForResult() using an intent that no app can When using the Camera intent to capture a photo, the picture is always taken in  To get full sized from the android camera, you need to use file provider as shown in example below. What generally happens when using camera to get photos is you only get the thumbnail quality image from the data.getExtras, so to get full size image you need to save it in phone storage first and then use that image.

How to Accessing the Camera and Take Pictures on Android , In this post, we're going to learn how we can access the camera and use it to We'll be using the system's Intent for taking pictures so we don't have to is unique and no two files would have a chance at being overwritten. Open up the Android Studio example project and select "Simple Camera Intent" from the navigation drawer. You should see something like this: A camera intent example. When you select "Take Photo," the external camera app will pop open and you are able to take an image.

  • I have an app that uses the mediarecorder to record video and its not that big. Isnt there something similar for taking images ? What i want is to get an image and overlay it with another bitmap to create a file.Please check out my full question on this matter…
  • What if i open the camera with camera =; and use Camera.takePicture() as seen on the documentation ?
  • @mremremre1: "I have an app that uses the mediarecorder to record video and its not that big" -- then I suspect that you're not handling all the devices. Getting the previews correct alone, for portrait/landscape plus rear-facing/FFC, takes a lot. "What if i open the camera with camera =; and use Camera.takePicture() as seen on the documentation ?" -- that's certainly the starting point.
  • Thanks i ll try it. Did you see the other question ? Because if there is a way to get a screenshot directly from the surfaceView i wont have to use the camera api
  • @mremremre1: AFAIK, you cannot take a screenshot of a SurfaceView.
  • Thank God for that :D