简体   繁体   中英

Querying MediaStore.Images.Media , how do I query both on EXTERNAL_CONTENT_URI and INTERNAL_CONTENT_URI?

And first of all thanks for your help.

I think this should be a rather trivial question for somebody not new to querying Content Providers.

I need to query MediaStore.Images.Media to obtain ALL the images on the device, both on internal storage and on an sd card.

This is the query I have in mind:

String[] proj = { MediaStore.Images.Media.DATA };

actualimagecursor = 
managedQuery(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, proj,null, null, null);

the point is that I want to query both EXTERNAL_CONTENT_URI and INTERNAL_CONTENT_URI.

Is it possible to perform it with a single query?

Sorry this is too old to help, but you can use MergeCursor to combine the two queries.

Cursor[] cursors = new Cursor[2];
cursors[0] = mActivity.getContentResolver().query(
    MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
    new String[]{
            MediaStore.Images.Media._ID,
            MediaStore.Images.Media.DATA,
            MediaStore.Images.Media.ORIENTATION,
            MediaStore.Images.Media.BUCKET_DISPLAY_NAME,
            MediaStore.Images.Media.BUCKET_ID,
            MediaStore.Images.Media.MIME_TYPE ,
    },
    null,
    null,
    MediaStore.Images.ImageColumns.DATE_TAKEN + " DESC"
);
cursors[1] = mActivity.getContentResolver().query(
    MediaStore.Images.Media.INTERNAL_CONTENT_URI,
       new String[]{
            MediaStore.Images.Media._ID,
            MediaStore.Images.Media.DATA,
            MediaStore.Images.Media.ORIENTATION,
            MediaStore.Images.Media.BUCKET_DISPLAY_NAME,
            MediaStore.Images.Media.BUCKET_ID,
            MediaStore.Images.Media.MIME_TYPE
       },
       null,
       null,
       MediaStore.Images.ImageColumns.DATE_TAKEN + " DESC"
);
Cursor cursor = new MergeCursor(cursors);

It's not possible to retrieve both results with a single query since the query is permofmed in a specific location (internal or external). You need yo instantiate two dirrefent Cursors .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM