1

Good day, i am trying to return images from different specific folders in an SD Card through a MediaStore Query. So far, i can successfully query for a single folder but am getting stuck in how to do it for multiple folders. code is like this:

cursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, img, 
     MediaStore.Images.Media.DATA + " like ? ", new String[]{"%" + "dcim" + "%"}, null);

i tried constructing something like this and other similar queries, but its not working:

cursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, img, 
MediaStore.Images.Media.DATA + " like ? ", new String[]{"%" + "dcim" + "%","%" + "downloads" + "%" }, null);

please any help will be appreciated. Thank you.

Rexx
  • 269
  • 1
  • 5
  • 16

2 Answers2

2

Should be something like that:

cursor = getContentResolver().query(
    MediaStore.Images.Media.EXTERNAL_CONTENT_URI, 
    img,
    MediaStore.Images.Media.DATA + " like ? OR "+MediaStore.Images.Media.DATA+" like ?", 
    new String[]{"%" + "dcim" + "%","%" + "downloads" + "%" }, 
    null);
Fedor
  • 43,261
  • 10
  • 79
  • 89
0

A one possible solution is to use multiple queries for every specific location and then join them with CursorJoiner like already showed here:

Android Can I use JOIN at mediastore query

Community
  • 1
  • 1
Michal Harakal
  • 1,025
  • 15
  • 21