0

I'm trying to show all thumbnails (path) stored locally in device.

I do it in two steps

  1. map <id, thumbnailPath>

    SparseArrayCompat<String> result = new SparseArrayCompat<String>();
    Cursor thumbCursor = null;
    thumbCursor = getContentResolver().query(
                MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,
                null,
                null,
                null, null);
    
    if (thumbCursor.moveToFirst()) {
        do {
            String path = thumbCursor.getString(thumbCursor
                    .getColumnIndex(MediaStore.MediaColumns.DATA));
            int imageId = thumbCursor.getInt(thumbCursor
                    .getColumnIndex(MediaStore.Images.Thumbnails.IMAGE_ID));
            result.put(imageId, path);
        } while(thumbCursor.moveToNext());
    }
    
    thumbCursor.close();
    
    return result;
    
  2. get all images' ids and iterate to get the thumbnail

    Cursor cursor = cr.query(
            Images.Media.EXTERNAL_CONTENT_URI, null,
             null, null, Images.ImageColumns.DATE_MODIFIED + " DESC");
    

    // retrieve thumbnail_path using the image's id (which is obtained from the above cursor)

However, some of images don't have thumbnail_path. (not found in the first mapping)
Not all images in gallery have a thumbnail image associated with it?

eugene
  • 39,839
  • 68
  • 255
  • 489
  • Why black? Is it realley a thumbnail or is path a null pointer? Or size 0? – greenapps Jul 14 '14 at 17:31
  • @greenapps: sorry, It was very ambiguous question, I edited it. – eugene Jul 15 '14 at 01:31
  • Are those missing thumbnails from Camera or other applications? Special paths? Investigate please. – greenapps Jul 15 '14 at 05:58
  • ah yes, they are not camera generated, they are tranferred from external camera using NFC. – eugene Jul 15 '14 at 07:04
  • You should -i think- have invoked MediaScanner on every file you transfered that way. – greenapps Jul 15 '14 at 07:10
  • You mean, something like http://stackoverflow.com/a/13270982/433570 ? I'm trying it, and doesn't seem that it generates a thumbnail.. – eugene Jul 15 '14 at 10:27
  • 1
    Yes something like that. Read http://stackoverflow.com/questions/23118167/android-mediascannerconnection-scanfile-failing-to-refresh-images-in-gallery I think, after that, the thumbnails will only be generated by the Gallery app (who else?) if you use the Gallery app to display the NFC images... but I'm not sure of that. You know who 'normaly' generates the thumbnails? If the MediaStore then you should add them there? – greenapps Jul 15 '14 at 10:34
  • @greenapps: I'm still stuck, and I posted what I found with mediascanner http://stackoverflow.com/questions/24801222/android-media-scan-doesnt-generate-thumbnails – eugene Jul 17 '14 at 10:39

0 Answers0