Gary Kipnis Gary Kipnis - 9 months ago 50
Android Question

How to query list of EMPTY bucket names in Android

I'd like to find all MediaStore buckets, including the ones that don't have any photos in them. All solutions, posted on SO, query for photos and then extract bucket names, but since the bucket is empty, there are no photos that will be returned by the query for that particular bucket. The Gallery App itself does not show empty Buckets/Folders.


BUCKET_ID is a property of the any media based on what provider considers as a media. BUCKET_ID is automatically computed from the DATA column of MediaStore.MediaColumns. DATA is path to the file on disk. So if there is no media in the directory there will be no DATA and as the result no BUCKET_ID property creation happens.

If you need to distinguish between empty and non-empty buckets by a property that they have in common, use their path file.getPath() as each directory has a unique path.

Imagine you have 10 directory on your device that have media inside them while maybe there are more than 1000 non-media contained directories on your device. So it is illogical if android search through all the existing directories on your device each time you query your MediaStore.

So the reason behind not assigning ids to empty directories from android is searching through ids of directories that have media inside them which is much faster, as the purpose of MediaStore is faster access to 'only media' files.