防止通过 Android 相机捕获的图像显示在图库中
我正在尝试将通过 Android 相机捕获的图像保存在自定义位置。我的代码如下所示:
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
File f = File(android.os.Environment.getExternalStorageDirectory(), "test.jpg");
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
startActivityForResult(intent, SUB_ACTIVITY_CAMERA_PREVIEW);
图像被保存到所需位置,但它也被保存到默认相机文件夹,这导致它显示在图库中。有什么建议吗?
I'm trying to save the image captured via android camera in a custom location. My code looks like this:
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
File f = File(android.os.Environment.getExternalStorageDirectory(), "test.jpg");
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
startActivityForResult(intent, SUB_ACTIVITY_CAMERA_PREVIEW);
The image is being saved to the desired location but it is also being saved to the default camera folder which is causing it to be displayed in the gallery. Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在外部文件目录中包含一个名为
.nomedia
的空文件(请注意文件名中的点前缀)。这将阻止 Android 的媒体扫描仪读取您的媒体文件并将其包含在图库或音乐等应用程序中。Include an empty file named
.nomedia
in your external files directory (note the dot prefix in the filename). This will prevent Android's media scanner from reading your media files and including them in apps like Gallery or Music.