How to capture a photo from the camera without intent

mremremre1 picture mremremre1 · Aug 17, 2013 · Viewed 9.4k times · Source

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;
    try
    {
        photo = this.createTemporaryFile("picture", ".jpg");
        photo.delete();
    }
    catch(Exception e)
    {
        Toast.makeText(getApplicationContext(),"Error",Toast.LENGTH_LONG).show();

    }
    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 ?

Answer

CommonsWare picture CommonsWare · Aug 17, 2013

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.