1

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.

1

3 Answers 3

6

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));
System.out.println("...path..."+path);
additionalFiles.add(path);
            }while(cursor.moveToNext());
                }
            if (cursor != null) {
                cursor.close();
            }
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
4
  • your code is working for folder but not for subfolder of folder. Dec 28, 2011 at 12:22
  • plz help me asap for getting images of sub folder of SD card's folder. Dec 28, 2011 at 13:24
  • give path of subfolder and check Dec 28, 2011 at 13:28
  • Thank it`s work for me but give the another problem out of memory? Oct 31, 2012 at 11:03
2

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()) {
            System.out.println(cursor.getString(cursor.getColumnIndex(Images.Media.DATA)));
            System.out.println(cursor.getString(cursor.getColumnIndex(Images.Media.DISPLAY_NAME)));

}
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.