简体   繁体   中英

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?

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.

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM