How to remove duplicate image in gallery when using Android camera?

I use the Android camera for shooting in my activity:

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); intent.putExtra(MediaStore.EXTRA_OUTPUT, getImagePath()); startActivityForResult(intent, TAKE_PHOTO_CODE); 

When I leave the camera application, the photo is saved in two places:

  • By the path specified by the getImagePath () method (which is correct);
  • To the gallery. I do not want it.

How to prevent saving photos in the gallery? And if I cannot do this, how can I get the path to the photo in my onActivityResult () to remove it?

+4
source share
2 answers

For Intent.ACTION_GET_CONTENT you can delete the gallery file (after copying to your folder). Perhaps this will work for MediaStore.ACTION_IMAGE_CAPTURE (with MediaStore.EXTRA_OUTPUT ). I use the following code snippet to delete a gallery file when returning from Intent.ACTION_GET_CONTENT :

 public String getRealPathFromURI(Uri contentUri) { String[] proj = { MediaStore.Images.Media.DATA }; Cursor cursor = managedQuery(contentUri, proj, null, null, null); int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); return cursor.getString(column_index); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { Uri u = data.getData(); new File(getRealPathFromURI(u)).delete(); ... 
+1
source

Do you save the image on the SD card somewhere in the getImagePath () code? If so, Android Media Scanner selects it from this location for display in the gallery. You can create an empty file named .nomedia in the directory where your images are saved so that Media Scanner ignores all media files in this folder.

0
source

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


All Articles