简体   繁体   English

使用 MediaStore 访问文件夹中的最近图像

[英]Accessing recent images in a folder using MediaStore

I am currently using this code to access the recent images from /DCIM/ folder -我目前正在使用此代码从/DCIM/文件夹访问最近的图像 -

final Cursor cursor = chatActivity.this.getContentResolver()
                .query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, null,
                        null, MediaStore.Images.ImageColumns.DATE_TAKEN + " DESC");

and then get the images by然后通过

if (cursor.moveToFirst()) {
    String imageLocation = cursor.getString(1);
    File imageFile = new File(imageLocation);
    if (imageFile.exists()) {
        Bitmap bm = BitmapFactory.decodeFile(imageLocation);
    }
}

and then using cursor.moveToNext() to access the next image.然后使用cursor.moveToNext()访问下一个图像。

But if I have to access the images in another folder (like /MyFolder/Images/ ) in a similar fashion, using MediaStore and Cursor then what should be done?但是,如果我必须使用MediaStoreCursor以类似的方式访问另一个文件夹(如/MyFolder/Images/ )中的图像,那么应该怎么做?

I have looked at Get MediaStore path of a Specific Folder and Displaying images from a specific folder on the SDCard using a gridview , they don't answer my question.我使用 gridview 查看了Get MediaStore path of a Specific FolderDisplaying images from a specific folder on SDCard ,他们没有回答我的问题。

With that code you are not only getting images from /DCIM/ folder but from all folders.使用该代码,您不仅可以从/DCIM/文件夹中获取图像,还可以从所有文件夹中获取图像。 If you want to get images from specific folder you can use something like this:如果要从特定文件夹中获取图像,可以使用以下内容:

final Cursor cursor = chatActivity.this.getContentResolver()
                .query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, MediaStore.Audio.Media.DATA + " like ?",
                        "%" + Environment.getExternalStorageDirectory().getAbsolutePath() + "/DCIM/%", MediaStore.Images.ImageColumns.DATE_TAKEN + " DESC");

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

相关问题 使用 MediaStore.Images.media 存储图像以保存在特定文件夹中 - STORING IMAGE using MediaStore.Images.media to save in a particular folder 如何使用 MediaStore 指定特定的图库文件夹 - how to intent specific gallery folder by using MediaStore 从MediaStore检索最近的歌曲 - Retrieving recent songs from the MediaStore 如何使用 MediaStore API 访问 Android 11 的 Whatsapp 文件夹? - How to access Whatsapp folder of Android 11 by using MediaStore API? 使用PImage获取最新文件夹(处理) - Get the most recent folder using PImage (processing) 如何在 android 工作室中使用 MediaStore Api 在 android 11 中获取特定文件夹,如 WhatsApp (.Status) 文件夹 - How to get specific folder like WhatsApp (.Status) folder in android 11 using MediaStore Api in android studio 从JAVA中的图像文件夹访问图像 - Accessing Images from image folder in JAVA 使用类加载器访问其他文件夹 - Accessing a different folder using classloader 如何使用 MediaStore 从具有路径、持续时间和缩略图的特定文件夹中获取所有视频? - How to get all video from specific folder with path,duration and thumbnail using MediaStore? 我们如何使用MediaStore类(ANDROID)获取所有包含图像的文件夹? - How do we get all folders containing images using MediaStore class (ANDROID)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM