Start a camera intent, but don't save image

2019-04-24 11:31发布

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?

2条回答
啃猪蹄的小仙女
2楼-- · 2019-04-24 11:39

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.

查看更多
对你真心纯属浪费
3楼-- · 2019-04-24 11:58

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();
查看更多
登录 后发表回答