简体   繁体   中英

How to load all the Images using Media Store?

I want to load all the Images present in the users device. I know that Images can be loaded using Media Store but the biggest drawback for me is that the Images which are present in the folder having .nomedia file are not loaded/retrieved using Media Store.

Is there an efficient way using Media Store or without using Media Store to load all the Images present in Android device irrespective of their parent folder having a .nomedia file?

This is how I am loading Images whose parent directory does not have .nomedia file:

public void getImages(Context context) {

        File Image_File;
        final String[] columns = {MediaStore.Images.Media.DATA, MediaStore.Images.Media._ID};

        String orderBy = MediaStore.Images.Media.DATE_MODIFIED ;

        Cursor cursor = context.getContentResolver().query(
                MediaStore.Images.Media.EXTERNAL_CONTENT_URI, columns, null,
                null, orderBy);

        if (cursor != null)
        {
            cursor.moveToFirst();
            final int dataColumnIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA);

            while (cursor.moveToNext()) {
                Image_File = new File(cursor.getString(dataColumnIndex));

               //Add the Image to the list
            }
        }

    }

I know that I can scan each and every folder and check if there is a Image present in it but it would consume a lot of time.

The MediaStrore does not scan directories which contain a .nomedia file.

So you cannot ask the MediaStore to deliver them.

You indeed have to make your own media store.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM