Every file type associated with its specific icon.
Now if i am choosing somefilename.xxx then how i could be able to choose the icon as
You can create a function that takes in a path, and by the file extension in its name, corresponds to the drawable.
fun getFileTypeIcon(path: String): Int {
val file = File(path)
val ext = MimeTypeMap.getFileExtensionFromUrl(file.name)
Log.i("ImagesExt", "$path ----> $ext")
return when (".$ext") {
".png", ".jpg", ".jpeg", ".gif", ".bmp" -> R.drawable.image
".mp3", ".wav", ".ogg", "midi" -> R.drawable.audio
".mp4", ".rmvb", ".avi", ".flv", ".3gp" -> R.drawable.video
".jsp", ".html", ".htm", ".js", ".php" -> R.drawable.web
".txt", ".c", ".cpp", ".xml", ".py", ".json", ".log" -> R.drawable.file
".xls", ".xlsx" -> R.drawable.file
".doc", ".docx" -> R.drawable.file
".ppt", ".pptx" -> R.drawable.file
".pdf" -> R.drawable.pdf
".jar", ".zip", ".rar", ".gz" -> R.drawable.zip
".apk" -> R.drawable.apk
else -> R.drawable.file
}
}