Reputation: 13442
I was browsing through some code that queries the MediaStore.Images content provider and uses a column named BUCKET_ID:
Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
String projection[] = {
"DISTINCT " + MediaStore.Images.Media.BUCKET_DISPLAY_NAME,
MediaStore.Images.Media.BUCKET_ID,
MediaStore.Images.Media.DATE_TAKEN,
MediaStore.Images.Media.DATA
};
String BUCKET_GROUP_BY = "1) GROUP BY 1,(2";
String BUCKET_ORDER_BY = "MAX(datetaken) DESC";
Cursor imagecursor = getContentResolver().query(uri, projection, BUCKET_GROUP_BY, null, BUCKET_ORDER_BY);
In general, what do these columns represent? Can anyone explain with examples?(The docs have a one-liner about these columns that explains quite less)
Upvotes: 2
Views: 6423
Reputation: 1723
BUCKET_DISPLAY_NAME
added to API level 29 String BUCKET_DISPLAY_NAME The bucket display name of the image. This is a read-only property that is automatically computed from the DATA column.
Type: TEXT
Constant Value: "bucket_display_name"
BUCKET_ID
added in API level 29 String BUCKET_ID The bucket id of the image. This is a read-only property that is automatically computed from the DATA column.
Type: TEXT
Constant Value: "bucket_id"
DATE_TAKEN
added to API level 29 String DATE_TAKEN The date & time that the image was taken in units of milliseconds since Jan 1, 1970.
Type: INTEGER
Constant Value: "datetaken"
Upvotes: 0
Reputation: 13442
Docs are vastly unclear on this and the above answer is a copy-paste from the docs. Anyway, I have found the answer from the source of Gallery 3D in form of comments:
// BUCKET_DISPLAY_NAME is a string like "Camera" which is the directory
// name of where an image or video is in. BUCKET_ID is a hash of the path
// name of that directory (see computeBucketValues() in MediaProvider for
// details). MEDIA_TYPE is video, image, audio, etc.
//
// The "albums" are not explicitly recorded in the database, but each image
// or video has the two columns (BUCKET_ID, MEDIA_TYPE). We define an
// "album" to be the collection of images/videos which have the same value
// for the two columns.
and here is the computeBucketValues()
for reference:
/**
* @param data The input path
* @param values the content values, where the bucked id name and bucket display name are updated.
*
*/
private static void computeBucketValues(String data, ContentValues values) {
File parentFile = new File(data).getParentFile();
if (parentFile == null) {
parentFile = new File("/");
}
// Lowercase the path for hashing. This avoids duplicate buckets if the
// filepath case is changed externally.
// Keep the original case for display.
String path = parentFile.toString().toLowerCase();
String name = parentFile.getName();
// Note: the BUCKET_ID and BUCKET_DISPLAY_NAME attributes are spelled the
// same for both images and video. However, for backwards-compatibility reasons
// there is no common base class. We use the ImageColumns version here
values.put(ImageColumns.BUCKET_ID, path.hashCode());
values.put(ImageColumns.BUCKET_DISPLAY_NAME, name);
}
Upvotes: 8