Stop saving images when an open camera uses Intent through my application

possible duplicate Stop saving photos using your own Android camera

Hi everyone, I open the camera using Intent in this way.

Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(cameraIntent, ACTIVITY_CAMERA); 

this is good and give me the result perfectly, but the problem is that it will also save the image in the SD card, how to prevent it, to stop saving the image and just use this data in the onActivityResult() method

+4
source share
1 answer

I'm not sure, but I will try. It can help you.

onActivityResult I am taking an image and then going to save it to another bitmap.

See this:

 if(resultCode == RESULT_OK && requestCode==TAKE_PHOTO_CODE){ final File file = getTempFile(this); try { tempBitmap = Media.getBitmap(getContentResolver(), Uri.fromFile(file)); photoBitmap = Bitmap.createScaledBitmap(tempBitmap, display.getWidth(), display.getHeight(), true); takePhotoFromCamera = true; // do whatever you want with the bitmap (Resize, Rename, Add To Gallery, etc) } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } 

Now you can delete the file after its bitmap. Therefore, it may not be saved on the SD card.

Give it a try. Hope this helps you.

or.,

Use this:

code to get the last image made by the user:

 String[] projection = new String[] {MediaStore.Images.ImageColumns._ID, MediaStore.Images.ImageColumns.DATA, MediaStore.Images.ImageColumns.BUCKET_DISPLAY_NAME, DATE_TAKEN, MediaStore.Images.ImageColumns.MIME_TYPE}; final Cursor cursor = managedQuery(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, null, null, DATE_TAKEN + " DESC"); 

After receiving this image, delete it. This will help you.

Enjoy. :))

+1
source

Source: https://habr.com/ru/post/1389992/


All Articles