我正试图从SD卡中检索特定文件夹中的图像。我能做的是从sdcard获取所有图像
代码:
onCreateLoader
方法:
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
String[] projection = {MediaStore.Files.FileColumns._ID,
MediaStore.Files.FileColumns.DATE_ADDED,
MediaStore.Files.FileColumns.MEDIA_TYPE
};
String selection = MediaStore.Files.FileColumns.MEDIA_TYPE + "="
+ MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE;
return new CursorLoader(getContext(), MediaStore.Files.getContentUri("external"), projection, selection, null,
MediaStore.Files.FileColumns.DATE_ADDED + " ASC");
}
答案 0 :(得分:2)
我正试图从SD卡中的特定文件夹中检索图像
将目录名称传递为selectionArgs
,并将选择字符串更改为:
String selection = MediaStore.Images.Media.DATA + " like ? ";
String selectionArgs =new String[] {"%PASS_DIR_NAME_HERE%"};
new CursorLoader(getContext(),MediaStore.Files.getContentUri("external"),
projection,
selection,
selectionArgs,
MediaStore.Files.FileColumns.DATE_ADDED + " ASC");
答案 1 :(得分:0)
您可以直接从decodeFile(String pathName)创建位图,该位图将为您提供可在ImageView上设置的位图对象。
File path = new File(Environment.getExternalStorageDirectory(),"iWallet/Images");
if(path.exists())
{
String[] fileNames = path.list();
}
for(int i = 0; i < filename.length; i++)
{
Bitmap mBitmap = Bitmap.decodeFile(path.getPath()+"/"+ fileNames[i]);
///Now set this bitmap on imageview
}