本文介绍了获取 Android 上的相册列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找:现有照片库名称的列表(希望它们的顶部缩略图也是如此)画廊的内容(然后我可以根据需要加载缩略图和全尺寸)

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)

我将如何获取画廊"列表(不知道这是否是 android 中画廊应用程序中可见图像分组的正确术语...)及其内容?我需要在不使用现有画廊显示的情况下访问其结构中的画廊(我正在创建一个全新的,而不是照片请求者的覆盖层等)

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.)

我认为 MediaStore.Images 是我需要的地方,但我看不到任何可以给我分组的东西...

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

推荐答案

分组由 MediaStore.Images.Media.BUCKET_DISPLAY_NAME 定义.以下是列出图像并记录其存储桶名称和拍摄日期的示例代码:

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
};

// content:// style URI for the "primary" external storage volume
Uri images = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;

// Make the query.
Cursor cur = managedQuery(images,
        projection, // Which columns to return
        null,       // Which rows to return (all rows)
        null,       // Selection arguments (none)
        null        // 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());

}

这篇关于获取 Android 上的相册列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 17:43