I'm making a query on the Android's MediaStore Files Database -MediaStore.Files.getContentUri("external")
- and, for some specific folders, both the MediaStore.MediaColumns.TITLE
, and MediaStore.MediaColumns.DISPLAY_NAME
are null while for other folders this value exists.
I couldn't find any documentation about MediaStore.MediaColumns.TITLE being possibly null.
This happens for a few internal Android directories, such as these:
_data: /storage/emulated/0/Music, title: null, _display_name: null
_data: /storage/emulated/0/Notifications, title: null, _display_name: null
_data: /storage/emulated/0/Pictures, title: null, _display_name: null
However, for some other folders, the title is there:
_data: /storage/emulated/0/Android, title: Android, _display_name: null
_data: /storage/emulated/0/DCIM, title: DCIM, _display_name: null
_data: /storage/emulated/0/Download, title: Download, _display_name: null
All data comes directly from the MediaStore query.
I am aware I could work directly with the Data but I'm trying to sort the query according to the TITLE, which leads to incorrect results given that some are null.
Is this an expected behaviour? How to deal with it and retrieve all files correctly sorted by title?
Looks like this is an android limitation. You could always try to do a order by such as this:
select substr(
substr(substr(MediaStore.MediaColumns.DATA, instr(MediaStore.MediaColumns.DATA, '/') + 1), instr(substr(MediaStore.MediaColumns.DATA, instr(MediaStore.MediaColumns.DATA, '/') + 1), '/') + 1),
instr(substr(substr(MediaStore.MediaColumns.DATA, instr(MediaStore.MediaColumns.DATA, '/') + 1), instr(substr(MediaStore.MediaColumns.DATA, instr(MediaStore.MediaColumns.DATA, '/') + 1), '/') + 1), '/') + 1
) from tablename;
Note that this is not recursive, but only works for up to 3 '/'.
This could be done recursively but it was only introduced later on Android
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With