0

我可以使用以下代码查询每张照片的Media._ID、Media.BUCKET_DISPLAY_NAME和DATE_TAKEN,但我只希望得到MediaStore.Images.Media.BUCKET_DISPLAY_NAME,我该怎么办?谢谢!

  // 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());
    }
4

1 回答 1

1
String[] projection = new String[]{
        MediaStore.Images.Media.BUCKET_DISPLAY_NAME
};

代替

String[] projection = new String[]{
        MediaStore.Images.Media._ID,
        MediaStore.Images.Media.BUCKET_DISPLAY_NAME,
        MediaStore.Images.Media.DATE_TAKEN
};

???

于 2014-04-11T17:25:35.847 回答