我正在浏览一些查询 MediaStore.Images 内容提供者并使用名为 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);
Run Code Online (Sandbox Code Playgroud)
一般来说,这些列代表什么?谁能用例子解释一下?(文档有一个关于这些列的单行说明,解释得很少)
文档对此非常不清楚,上面的答案是从文档中复制粘贴的。无论如何,我以评论的形式从Gallery 3D的来源中找到了答案:
// 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.
Run Code Online (Sandbox Code Playgroud)
这是computeBucketValues()供参考:
/**
* @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);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4315 次 |
| 最近记录: |