Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve images of particular folder in Android

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!

like image 931
void Avatar asked Feb 13 '13 16:02

void


People also ask

How do I get a list of images in a specific folder on Android?

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().

How do you get an image from a camera or a gallery and save it in Android?

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).


1 Answers

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"));
    }
});
like image 143
praveen s Avatar answered Nov 08 '22 07:11

praveen s