Reputation: 164
I m trying to retrieve images from a particular folder from sd card. what i m able to do is getting all the images from sdcard
code:
onCreateLoader
method:
@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");
}
Upvotes: 0
Views: 2213
Reputation: 186
You can directly create Bitmaps from decodeFile (String pathName) that will give you Bitmap object that can be set on 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
}
Upvotes: 0
Reputation: 132992
I m trying to retrieve images from a particular folder from sd card
Pass directory name as selectionArgs
and change selection String as:
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");
Upvotes: 2