Get list of photo galleries on Android

11down votefavorite

10

I'm looking for: A list of the existing photo gallery names (hopefully their top thumbnail as well) The contents of the gallery (I can then load thumbnails and full size as needed)

How would I go about getting a list of the "Galleries" (don't know if that's the proper term in android for the groupings of images visible in the Gallery app...) and their contents? I need access to the gallery in it's structure without using the existing gallery display (I'm creating a totally new one, not an over layer to the photo requestor etc.)

I assume MediaStore.Images is where I need to be but I don't see anything that will give me the groupings...

android image gallery mediastore

share|improve this question

asked Nov 16 '10 at 15:18

ima747
99411028


add comment

1 Answer

activeoldestvotes

up vote25down voteaccepted

Groupings are defined by MediaStore.Images.Media.BUCKET_DISPLAY_NAME. Here is the sample code to list the images and log their bucket name and date_taken:

    // which image properties are we querying
    String[] projection = new String[]{
            MediaStore.Images.Media._ID,
            MediaStore.Images.Media.BUCKET_DISPLAY_NAME,
            MediaStore.Images.Media.DATE_TAKEN    };

    // Get the base URI for the People table in the Contacts content provider.
    Uri images = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;

    // Make the query.
    Cursor cur = managedQuery(images,
            projection, // Which columns to return
            "",         // Which rows to return (all rows)
            null,       // Selection arguments (none)
            ""          // Ordering
            );

    Log.i("ListingImages"," query count="+cur.getCount());

    if (cur.moveToFirst()) {
        String bucket;
        String date;
        int bucketColumn = cur.getColumnIndex(
            MediaStore.Images.Media.BUCKET_DISPLAY_NAME);

        int dateColumn = cur.getColumnIndex(
            MediaStore.Images.Media.DATE_TAKEN);

        do {
            // Get the field values
            bucket = cur.getString(bucketColumn);
            date = cur.getString(dateColumn);

            // Do something with the values.
            Log.i("ListingImages", " bucket=" + bucket 
                   + "  date_taken=" + date);
        } while (cur.moveToNext());

    }

share|improve this answer

answered Nov 16 '10 at 16:27

Peter Knego
54k74986




AH! it works like a raw database query. perfect example code thank you! –  ima747 Nov 16 '10 at 18:46


你可能感兴趣的:(android,gallery,相册)