I am creating (trying) a file manager app and i want to show recent files (all types) on main activity. I tried many answers that only shows how to get only one type of media files. Is there any way to get all type of recent media files.
I tried to modify answers i found online but it's giving null as display name.
val projection = arrayOf(
MediaStore.Files.FileColumns._ID,
MediaStore.Files.FileColumns.DISPLAY_NAME,
MediaStore.Files.FileColumns.DATE_ADDED,
MediaStore.Files.FileColumns.SIZE
)
val sortOrder = "${MediaStore.Files.FileColumns.DATE_ADDED} ASC limit 10"
applicationContext.contentResolver.query(
MediaStore.Files.getContentUri(MediaStore.VOLUME_INTERNAL),
projection,
null,
null,
sortOrder
)?.use { cursor ->
Log.e("TAG", ">> " + cursor.count)
val idColumn = cursor.getColumnIndexOrThrow(MediaStore.Files.FileColumns._ID)
val nameColumn = cursor.getColumnIndexOrThrow(MediaStore.Files.FileColumns.DISPLAY_NAME)
while (cursor.moveToNext()) {
Log.e("TAG", ">> " + cursor.getLong(idColumn))
Log.e("TAG", ">> " + cursor.getString(nameColumn))
}
}