Java – starts the camera intent, but does not save the image

Is there any way to use the camera, but only save the image temporarily? I'm loading the camera using the following code, and then I use onactivityresult() to get the image (if any...)

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

The problem is that when an image is 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 the data I am using (onactivityresult)

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

The image will never be deleted In addition, if I enter my gallery application and there is a default name in the image (such as image57465. JPG), I want to know cameraintent putExtra(MediaStore.EXTRA_OUTPUT,outputFileUri); Actually, there is no job

Edit 2

In fact, the file is being saved to the sdcard and deleted correctly However, it appears that thumbnails are being saved Do I want to know how to get the thumbnail path so that I can delete it after using it?

Solution

Well, can't you delete the image after using it? I just checked the camera API specification quickly, but I can't find anything to indicate that you can mark images as temporary images

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

        }

    }

}

If it suits you, please let me know

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>