Take the 2-minute tour ×

Following code is used to get images from particular folder but how to get sub folder's images of sdcard's folder.

Cursor actualimagecursor = managedQuery(
    MediaStore.Images.Media.EXTERNAL_CONTENT_URI, proj,
    MediaStore.Images.Media.DATA + " like ? ",
    new String[] { "%unzipped%" }, null);

Sorry for bad English communication.

share|improve this question
add comment

3 Answers

up vote 4 down vote accepted

Try with the following code

public void searchImageFromSpecificDirectory() {

        String path = null;

        String uri = MediaStore.Images.Media.DATA;
        // if GetImageFromThisDirectory is the name of the directory from which image will be retrieved
        String condition = uri + " like '%/GetImageFromThisDirectory/%'";
        String[] projection = { uri, MediaStore.Images.Media.DATE_ADDED,
                MediaStore.Images.Media.SIZE };
        Vector additionalFiles = null;
        try {
            if (additionalFiles == null) {
                additionalFiles = new Vector<String>();

            Cursor cursor = managedQuery(
                    MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection,
                    condition, null, null);
            if (cursor != null) {

                boolean isDataPresent = cursor.moveToFirst();

                if (isDataPresent) {

                    do {

                        path = cursor.getString(cursor.getColumnIndex(uri));
            if (cursor != null) {

        } catch (Exception e) {
share|improve this answer
your code is working for folder but not for subfolder of folder. –  Dipak Keshariya Dec 28 '11 at 12:22
plz help me asap for getting images of sub folder of SD card's folder. –  Dipak Keshariya Dec 28 '11 at 13:24
give path of subfolder and check –  Sunil Kumar Sahoo Dec 28 '11 at 13:28
Thanks for help Sunilkumar. –  Dipak Keshariya Dec 28 '11 at 14:02
not working for me/? –  Abdul Wahab Jul 27 '12 at 12:01
show 1 more comment

Try this code below : In images folder contains Sample sub folder.

Cursor cursor = managedQuery(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, null,Images.Media.DATA + " like '/mnt/sdcard/Images/Sample%'", null, null);

while (cursor.moveToNext()) {

share|improve this answer
add comment

I wanna give you one suggestion, See if you want to watch a particular Directory suppose /sdcard/. Then Use FileObserver class and make it recursive for every subdirectory. It will help you for sure. Try it.Make stack or ArrayList which will store all the directories in /sdcard/ and than startWatching for all directories.

share|improve this answer
add comment

Your Answer


