Dipak Keshariya
Dipak Keshariya

Reputation: 22291

How to Getting Images from Sdcard's folder's Subfolder?

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.

Upvotes: 1

Views: 5529

Answers (3)

Suresh
Suresh

Reputation: 8363

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.

Upvotes: 0

Sandy
Sandy

Reputation: 428

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

}

Upvotes: 2

Sunil Kumar Sahoo
Sunil Kumar Sahoo

Reputation: 53687

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();
        }
    }

Upvotes: 6

Related Questions