Android MediaStore Insert Image Additional file created

不打扰是莪最后的温柔 提交于 2019-12-22 10:47:24

问题


I am inserting an Image in the MediaStore cache using the following code snippet:

MediaStore.Images.Media.insertImage(getContentResolver(), selectedFile.getParent() + file.separator + selectedFile.getName(), selectedFile.getName(),null);

The insertion is ok but it also creates another image thumbnail at the same path. This is not visible in the gallery but when browsed using file browser this image thumbnail is visible. How can I stop this image thumbnail to be created here so as not to confuse the user.


回答1:


The documentation for MediaStore.Images.Media.insertImage() says that it:

Insert an image and create a thumbnail for it.

What you actually need to do is to access the Media Scanner Service. The service runs by default during startup or after inserting the SD card. You can force it to run using intents but you end up rescanning the entire SD card for a single.

There is, of course, a better solution:

If you're developing for API level 8 or higher (Android 2.2), use the scanFile static function from MediaScannerConnection, documented here.

For API 7 or lower, it's a bit more complicated but you can put everything together with a wrapper best explained in the following post: dynamically add pictures to gallery widget



来源:https://stackoverflow.com/questions/4773175/android-mediastore-insert-image-additional-file-created

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!