Search code examples
androidandroid-contentresolver

How can I get a listing of all directories with videos on them?


Using the Android ContentResolver I can get a Cursor that gives me video files, and that works nicely, but I see that a lot of apps separate that media by directory.

How do they figure out what directories have media without looping all of the items the cursor returns? Or is that the only way to do it?

Thanks.

Edit: Just to be clear, I already have code that queries all videos, loops through each one of them and extract the directories. Just seems silly that this is the only way to do it.


Solution

  • There is currently no way to go from a cursor result to a list directly without looping. Cursors are lazy by design and don't have a native map functionality. Anko provides a parseList to abstract the loop (and close the cursor) and return you the desired list.

    In re: the original question though. Due to there being multiple Uri buckets that content can live in (Documents, Downloads, etc) there isn't a single Uri to collate the result. You might be able to join the Uris in your query though?