Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to capture a photo from the camera without intent

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 ?

like image 555
mremremre1 Avatar asked Aug 17 '13 17:08

mremremre1


1 Answers

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.

like image 91
CommonsWare Avatar answered Sep 23 '22 00:09

CommonsWare