简体   繁体   English

查询 MediaStore.Images.Media ,如何同时查询 EXTERNAL_CONTENT_URI 和 INTERNAL_CONTENT_URI?

[英]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.我需要查询MediaStore.Images.Media以获取设备上的所有图像,包括内部存储和 SD 卡。

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.问题是,我想查询EXTERNAL_CONTENT_URI和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.抱歉,这太旧了,无法提供帮助,但您可以使用 MergeCursor 来组合这两个查询。

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 .你需要你实例化两个 dirrefent Cursors

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 EXTERNAL_CONTENT_URI和INTERNAL_CONTENT_URI都从Android的内部存储卡中提取视频 - EXTERNAL_CONTENT_URI and INTERNAL_CONTENT_URI both fetch videos from internal memory card in android MediaStore.Images.Media.INTERNAL_CONTENT_URI返回空游标 - MediaStore.Images.Media.INTERNAL_CONTENT_URI returns empty cursor Android 9 (Pie) ContentResolver 查询 MediaStore.Images.Media.EXTERNAL_CONTENT_URI 在 api 28 上返回 null - Android 9 (Pie) ContentResolver query MediaStore.Images.Media.EXTERNAL_CONTENT_URI returns null on api 28 Android中EXTERNAL_CONTENT_URI的文件路径 - Filepath of EXTERNAL_CONTENT_URI in Android MediaStore.Audio.Media.EXTERNAL_CONTENT_URI报告为未知URI - MediaStore.Audio.Media.EXTERNAL_CONTENT_URI reported as Unknown URI 在查询`MediaStore.Audio.Media.EXTERNAL_CONTENT_URI`之前,有没有办法强制系统媒体重新扫描? - Is there any way to force a system media rescan before querying `MediaStore.Audio.Media.EXTERNAL_CONTENT_URI`? 使用EXTERNAL_CONTENT_URI从图库中选择的图像中缺少EXIF信息 - Missing EXIF info in images selected from gallery using EXTERNAL_CONTENT_URI MediaStore.Audio.Media.EXTERNAL_CONTENT_URI返回一个空游标 - MediaStore.Audio.Media.EXTERNAL_CONTENT_URI return an empty cursor ContentResolver 插入 MediaStore.Audio.Media.EXTERNAL_CONTENT_URI 错误 - ContentResolver insert MediaStore.Audio.Media.EXTERNAL_CONTENT_URI error Android:MediaStore.Images.Media.EXTERNAL_CONTENT_URI…以全尺寸显示图片吗? - Android: MediaStore.Images.Media.EXTERNAL_CONTENT_URI … show pictures in full size?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM