Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Start a camera intent, but don't save image

Is there a way to use the camera, but only temporarily save the image? I'm using the following code to load up the camera, then I'm using onActivityResult() to get the image taken (if any...)

Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);

the problem is that when the image gets taken, it is saved to the SD card.

EDIT

The intent is called by the following code

String imagePath;

imagePath = Environment.getExternalStorageState() + "/images/myimage.jpg";
File file = new File( imagePath );
Uri outputFileUri = Uri.fromFile( file );

Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra( MediaStore.EXTRA_OUTPUT, outputFileUri );
startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);

When the activity returns data (onActivityResult) I'm using

File imageFile = new File(imagePath);
imageFile.delete();

Howver the image never gets deleted. Also, if i head into my gallery application, the image is in there was a default name (like image57465.jpg), I'm asuming the cameraIntent.putExtra( MediaStore.EXTRA_OUTPUT, outputFileUri ); is not actually working.

EDIT 2

Actually, the file is being saved to the SDCARD, and deleted correctly. However, it seems that the thumbnail is being saved. Ay idea how to get the thumbnail path so i can delete it after i've used it?

like image 643
dotty Avatar asked Aug 14 '11 10:08

dotty


2 Answers

Well, can't you just delete the image when you're done using it? I just quick-checked the Camera API-specification, and I couldn't quite find anything that indicates that you can flag an image as temporary.

Try the following:

public onActivityResult(int request, int result, Intent data) {

    if( request == CAPTURE_IMAGE ) {

        if( result == RESULT_OK ) {

            /*Use the image in the way you want to here and save the path */

            //Delete the image
            File image = new File(path);
            image.delete();

        }

    }

}

Let me know if it works out for you.

like image 127
karllindmark Avatar answered Sep 30 '22 15:09

karllindmark


At the time of capture & saving, store imagepath to the variable and once your activity is done then remove the file(variable) from the storage

File mFile=new File(variable);
mfile.delete();
like image 20
Mohammed Azharuddin Shaikh Avatar answered Sep 30 '22 15:09

Mohammed Azharuddin Shaikh