So Here's the scenario
Iterate through a folder, and replace all the images with another set of images.
What I expect : Image to be updated in my gallery as well as it's thumbnail.
What I get : When I open my gallery the old image thumbnail is still there. When I open the image, the replaced version of that image appears. And to make it even stranger, some of the images, when you open them, there is a quick flash of the previous original image, followed by the replaced version, and if you zoom in on that photo, "surprise" it's the old photo again (Note : this is only with some images. - Not all). All images though, doesn't have an updated thumbnail.
Give it 10 minutes and bam!, all images has been refreshed with no trace of the old original ones.
No clue why it doesn't do it instantaneously.
I Have also followed the instructions here. But the same problem persist.Trigger scan whole folder Latest API doesn't allow scanning for whole folder besides the system doing that, since some apps scanned a folder because just one image changed thus draining battery life.
My Code
//originalImagesList is the list of filepaths for all the images in a specific folder
for (String s :originalImagesList)
{
try
{
File checkIfFile = new File(s);
//replacementAppImg contains a list of images used to replace other images with
Log.v(TAG, "Moving file From Replace - " + replacementAppImg.get(1));
Log.v(TAG, "Moving file to Replace - " + s);
InputStream in = new FileInputStream(replacementAppImg.get(1)); //From where
OutputStream out = new FileOutputStream(s); //To where
//Copy the bits from instream to outstream
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
Intent mediaScannerIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
//checkIfFile is the new replaces image that i want to refresh/check
Uri fileContentUri = Uri.fromFile(checkIfFile);
mediaScannerIntent.setData(fileContentUri);
CustomSettings.getCustomAppContext().sendBroadcast(mediaScannerIntent);
} catch (Exception ex) {
Log.v(TAG2,"Exception 1 - " + ex.toString());
}
}