1

I am using this technique to get a list of photo buckets or galleries in Android

Get list of photo galleries on Android

However, this iterated through each image and is slow for 1000+ images.

Is there a way to use SQL (maybe DISTINCT keyword?) to get the list of BUCKET_DISPLAY_NAMEs more quickly?

Community
  • 1
  • 1
Milk Run
  • 17
  • 8

2 Answers2

2

The below solution is what worked for me. I found that doing a distinct in the projections was not an option for the Media content provider. Also, this seems to work with a cursorLoader.

        // TODO Auto-generated method stub
    String[] projection = { Images.Media._ID, Images.Media.BUCKET_DISPLAY_NAME };

    HashMap<String, String> imagesGroups = new HashMap<String, String>();
    String ids = null;

    Cursor c = _myContext.getContentResolver().query(Images.Media.EXTERNAL_CONTENT_URI, projection, null, null, null);
    if (c.getCount() > 0)
    {
        c.moveToFirst();
        do
        {
            String bucketDisplayName = c.getString(c.getColumnIndex(Images.Media.BUCKET_DISPLAY_NAME));
            String _id = c.getString(c.getColumnIndex(Images.Media._ID));

            //here is where we ensure we get a unique image id for each distinct bucket display name
            if(!imagesGroups.containsKey(bucketDisplayName))
            {
                imagesGroups.put(bucketDisplayName, _id);

                if(ids == null)
                    ids = _id;
                else
                    ids += "," + _id;
            }
        }
        while (c.moveToNext());
    }

    c.close();

    String selection = Images.Media._ID + " IN (" + ids + ")";

    CursorLoader cursorLoader = new CursorLoader(this, Images.Media.EXTERNAL_CONTENT_URI, projection, selection, null, null);
    return cursorLoader;
0

We have to use lazyloading concept when using more images. If this is want you want take a look at http://androidsnips.blogspot.in/2010/08/lazy-loading-of-images-in-list-view-in.html or http://thinkandroid.wordpress.com/2012/06/13/lazy-loading-images-from-urls-to-listviews/ When using this concept the images that are loaded for the first time gets stored in the memory and if the same image is obtained again it will be checked and displayed directly without loading again. Hope this is want you need

G_S
  • 7,068
  • 2
  • 21
  • 51