I'm making a file manager in which picture items have a small thumbnail.
I get thumbnail image by using MediaStore
. Everything works fine. But when I rename or move a file, the thumbnail does not show up.
I've found a piece of code to refresh MediaStore
:
getActivity().sendBroadcast(
new Intent(Intent.ACTION_MEDIA_MOUNTED,
Uri.parse("file://" + Environment.getExternalStorageDirectory())));
It worked but I must wait 4 or 5 second and refresh, then the thumbnail updates.
How to get thumbnail of image immediately after rename or moving?
YouTube may disable custom thumbnails for certain search results when they're considered inappropriate for viewers. All custom thumbnail images must follow our Community Guidelines.
A Youtube thumbnail normally changes in less than 10 secs if you have a good internet connection.
How long does YouTube thumbnail take to update? After uploading thumbnails for YouTube video and save change, your thumbnail change comes in effect within 8-10 seconds.
If you cannot upload a picture, then try first uninstalling the YouTube app, deleting the cache and then downloading it again, or uninstalling updates for it, and then clearing the cache and updating.
What happen if you use ACTION_MEDIA_SCANNER_SCAN_FILE instead of ACTION_MEDIA_MOUNTED
, (i.e. trigger a refresh for a single file instead of for the complete directory hierarchy) ?
You will need to replace the URI of the directory with the URI of the file, obtained for example using Uri.fromFile().
When you move or rename a file you should refresh the old and the new URIs.
The recommended way to update one specific image in Android is using ACTION_MEDIA_SCANNER_SCAN_FILE intent. And for smoother
You can check it at Basic Photo Handling Training in Android Developer Site.
private void galleryAddPic() {
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
File f = new File(mCurrentPhotoPath);
Uri contentUri = Uri.fromFile(f);
mediaScanIntent.setData(contentUri);
this.sendBroadcast(mediaScanIntent);
}
If you want to show new thumbnail immediately for some missing files, you can do it by yourself. First, check the MediaStore as before, and if the returned thumbnail is null then generate your own one using ThumbnailUtils or BitmapFactory.
And, For handling a bitmap and displaying it, there is a quiet straightforward sample in Android Training Course.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With