[英]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?但是,如果我必须使用
MediaStore
和Cursor
以类似的方式访问另一个文件夹(如/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 Folder和Displaying 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.