Android的MediaStore插入图片的其他文件创建 [英] Android MediaStore Insert Image Additional file created

查看:198
本文介绍了Android的MediaStore插入图片的其他文件创建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用下面的code片段插入在MediaStore缓存图像:

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

MediaStore.Images.Media.insertImage(getContentResolver(),selectedFile.getParent()+文件分割符+ 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.

推荐答案

的文档 MediaStore.Images.Media.insertImage()说的:

插入图像,并创建一个缩略图   吧。

Insert an image and create a thumbnail for it.

你真正需要做的是访问媒体扫描服务。 该服务在启动时或插入SD卡后,默认运行。您可以强制其使用意图运行,但你最终重新扫描整个SD卡一个。

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:

如果您正在开发的API级别8或更高版本(Android 2.2的),使用 SCANFILE 静态函数从 MediaScannerConnection ,文件<一个href="http://developer.android.com/reference/android/media/MediaScannerConnection.html#scanFile%28java.lang.String,%20java.lang.String%29">here.

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

有关API 7或更低,这是一个比较复杂一点,但你可以把所有的东西连同包装最好在下面的帖子解释说: <一href="http://stackoverflow.com/questions/4157724/dynamically-add-pictures-to-gallery-widget">dynamically将图片添加到库部件

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

这篇关于Android的MediaStore插入图片的其他文件创建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆