user586250
user586250

Reputation: 33

Android MediaStore Insert Image Additional file created

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.

Upvotes: 3

Views: 6498

Answers (1)

Mircea Nistor
Mircea Nistor

Reputation: 3260

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

Upvotes: 6

Related Questions