1

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.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Rajesh K
  • 683
  • 2
  • 9
  • 35

1 Answers1

0

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.

greenapps
  • 11,154
  • 2
  • 16
  • 19
  • Thanks for the answer. Is it possible to get the list of all the files using Media Store which may include images whose parent directory has a `.nomedia` file. So that then I can take out the list of only Images. There are some apps which load hidden images without consuming a lot of time. – Rajesh K Dec 30 '17 at 12:04
  • Can you please provide me with an example on how to create own Media Store . – Rajesh K Jan 01 '18 at 09:49
  • What is the problem doing so? Scan the 'drives' for such files. – greenapps Jan 01 '18 at 11:05
  • OK. Thanks for the answer. Can I do it using this answer https://stackoverflow.com/a/14676430/9155610 – Rajesh K Jan 01 '18 at 11:58
  • Yes. That is the idea. – greenapps Jan 01 '18 at 15:59
  • Why dont you just remove those .media files on your device? I would not like the idea that your app would scan directories wit a .nomedia file in it. Bad idea. Are you telling the users of your app that you do such nasty things? – greenapps Jan 01 '18 at 16:02
  • Yes the Medias will be shown to the users. The users would know that the scan is going on for Media including `.nomedia` Media and after the scan is completed the users will be notified about it. – Rajesh K Jan 01 '18 at 16:54