In my application I created the GridView
to show the image from particular folder.
The issue is that I want to retrieve images from the DCIM/100ANDRO folder.
Which type of arguments should be passed through query to retrieve such type of images?
Please provide me solution.
I am using following code to retrieve which gives me images captured by camera
//importing only camera images and storing in ArrayList of class Images type
String[] projection = {
MediaStore.Images.Media._ID, MediaStore.Images.Media.BUCKET_DISPLAY_NAME,
MediaStore.Images.Media.DISPLAY_NAME
};
String selection = MediaStore.Images.Media.BUCKET_DISPLAY_NAME + " = ?";
String[] selectionArgs = new String[] {
"Camera"
};
Cursor mImageCursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, selection, selectionArgs, null );
if (mImageCursor != null)
{
mImageCursor.moveToFirst();
for (int i = 0; i < mImageCursor.getCount(); i++)
{
Images im=new Images();
eachImageView=new ImageView(this);
int imageId = mImageCursor.getInt((mImageCursor.getColumnIndex( MediaStore.Images.Media._ID)));
Bitmap bm = MediaStore.Images.Thumbnails.getThumbnail(getContentResolver(),
imageId, MediaStore.Images.Thumbnails.MINI_KIND, null);
im.setBitmap(bm);
eachImageView.setImageBitmap(bm);
im.setImageView(eachImageView);
arrayOfImages.add(im);
mImageCursor.moveToNext();
}
}
Suggestion will be appreciated!
You can use below code to get all images from specific folder. 1) First you need to define File object to get the storage and appened the name of the folder you want to read. File folder = new File(Environment. getExternalStorageDirectory().
Run the application on an Android phone. Selecting "Take photo" will open your camera. Finally, the image clicked will be displayed in the ImageView. Selecting "Choose from Gallery" will open your gallery (note that the image captured earlier has been added to the phone gallery).
File folder = new File(Environment.getExternalStorageDirectory().toString() + "/Folder Name/");
folder.mkdirs();
File[] allFiles = folder.listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
return (name.endsWith(".jpg") || name.endsWith(".jpeg") || name.endsWith(".png"));
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With