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.

Dipak Keshariya
  • 22,193
  • 18
  • 76
  • 128

3 Answers3

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();
        }
    }
Sunil Kumar Sahoo
  • 53,011
  • 55
  • 178
  • 243
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)));

}
ManuPK
  • 11,623
  • 10
  • 57
  • 76
Sandy
  • 428
  • 1
  • 5
  • 16
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.

Suresh
  • 7,785
  • 1
  • 16
  • 28