开发者

How to Remove duplicated picture in gallery when using android camera?

I use the Android camera to take a picture 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 app, the photo is saved in two places:

  1. At the path specified by the getImagePath() method (which is correct) ;
  2. Into the gallery. I don't whant that.

How can I prevent the photo to be saved into the gallery? And if I can't do it, how can I get the photo path in my onActivityResult(开发者_如何学Python) so I can delete it?


For Intent.ACTION_GET_CONTENT you can delete the gallery file (after copying it to your folder). Perhaps this would also work for MediaStore.ACTION_IMAGE_CAPTURE (with MediaStore.EXTRA_OUTPUT). I use the following code snippet for deleting the gallery file on return 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();
  ...


Are you saving the image to the SD card somewhere in your getImagePath() code? If so, the Android Media Scanner is picking it up from that location to display in the gallery. You can create an empty file named .nomedia in the directory where your images are saved to have the Media Scanner ignore all the media files in that folder.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜