使用Android相机时如何删除图库中的重复图片?
我在 Activity 中使用 Android 相机拍照:
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, getImagePath());
startActivityForResult(intent, TAKE_PHOTO_CODE);
当我离开相机应用程序时,照片保存在两个位置:
- getImagePath() 方法指定的路径(这是正确的);
- 进入画廊。我不想要那个。
如何防止照片被保存到图库中?如果我做不到,如何在 onActivityResult() 中获取照片路径以便将其删除?
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:
- At the path specified by the getImagePath() method (which is correct) ;
- 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() so I can delete it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于
Intent.ACTION_GET_CONTENT
,您可以删除图库文件(将其复制到文件夹后)。也许这也适用于MediaStore.ACTION_IMAGE_CAPTURE
(使用MediaStore.EXTRA_OUTPUT
)。我使用以下代码片段在从Intent.ACTION_GET_CONTENT
返回时删除图库文件:For
Intent.ACTION_GET_CONTENT
you can delete the gallery file (after copying it to your folder). Perhaps this would also work forMediaStore.ACTION_IMAGE_CAPTURE
(withMediaStore.EXTRA_OUTPUT
). I use the following code snippet for deleting the gallery file on return fromIntent.ACTION_GET_CONTENT
:您是否在 getImagePath() 代码中将图像保存到 SD 卡中?如果是这样,Android 媒体扫描程序将从该位置拾取它以显示在图库中。您可以在保存图像的目录中创建一个名为 .nomedia 的空文件,以使媒体扫描程序忽略该文件夹中的所有媒体文件。
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.