Check Uri Is Image

June 19, 2018
fun isImage(context: Context, uri: Uri): Boolean {
    val mimeType = context.contentResolver.getType(uri) ?: return true
    return mimeType.startsWith("image/")

NOTE: if MIME is null, the code above assume is image. Feel free to change it to fit your use case.

This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.