androidandroid-gallery

Image Thumbnail Refresh in Gallery


For my application, I need to refresh thumbnail image of gallery.

Because whenever I update my image content that thing don't reflected on thumbnail. The thumbnail image show first time image creation data not the present one.

But actual image contain new data so I need to reflect it into thumbnail also. After wandering this forum I found following code snippet to delete current thumbnail but I can't able to call this function because I don't able to get photoId.

private static void removeThumbnails(ContentResolver contentResolver, long photoId) {
       Cursor thumbnails = contentResolver.query(Thumbnails.EXTERNAL_CONTENT_URI, null,           Thumbnails.IMAGE_ID + "=?", new String[]{String.valueOf(photoId)}, null);
       for (thumbnails.moveToFirst(); !thumbnails.isAfterLast(); thumbnails.moveToNext())    {
          long thumbnailId = thumbnails.getLong(thumbnails.getColumnIndex(Thumbnails._ID));
          String path = thumbnails.getString(thumbnails.getColumnIndex(Thumbnails.DATA));
          File file = new File(path);
          if (file.delete()) {
                 contentResolver.delete(Thumbnails.EXTERNAL_CONTENT_URI, Thumbnails._ID + "=?", new String[]{String.valueOf(thumbnailId)});
       }
}

At present I was calling this function as

removeThumbnails(pexelMimics.getContentResolver(),
            ContentUris.parseId(uri));

I think this trick will work for me. But this is my guess. I am open to better solutions.


Solution

  • At the time of image saving, I have to provide following code to delete image content.

    activity.getContentResolver().delete(
                MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                MediaColumns.DATA
                        + "='"
                        + GameManager.getInstance().getSavedImageFilePath()
                                .replaceAll("'", "''") + "'", null);
    

    After this I got new content in thumbnail icon.