1

I'm developing an Android app that scans for images inside all the device folders and subfolders. I want it to return only photos or saved images but it is returning me also app images like buttons, arrows and others. I'm currently filtering for path name like filePath.contains("cache") and other similar to this, to remove cached images that I don't need. I wonder if there was a way to recognize app paths or app images correctly, like gallery apps do.

Thank you in advance.

  • If it can help you, here's how an open source gallery app do it: https://github.com/SimpleMobileTools/Simple-Gallery/blob/master/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt. (It's written in Kotlin) – Nicolas Jun 14 '18 at 21:13
  • Do you want to just scan for user-added images (i.e. gallery, camera, downloads, etc.)? If so, you can probably use the MediaStore content resolver to fetch and list those files. Check out: https://stackoverflow.com/a/4196411/394933 – Brian Jun 14 '18 at 21:37

1 Answers1

0

Assuming you are checking for all the device image files by querying the MediaStore using the Uri MediaStore.Files.getContentUri("external"), you only need to ensure to place in the query selection MediaStore.Files.FileColumns.MEDIA_TYPE, and as selection arguments MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE. This way only the files which have been scanned by the OS as photo files will be returned.

PerracoLabs
  • 16,449
  • 15
  • 74
  • 127