Check for xml file extension
val resourceId = R.drawable.ic_check_white_24dpval value = TypedValue()resources.getValue(R.drawable.ic_check_white_24dp, value, true)// value.string = res/drawable/ic_check_white_24dp.xmlval fileExt = value.string.toString().substringAfterLast(".", "")if (fileExt == "xml") { // probably a vector image}
Use Kotlin Extension
fun Resources.getFileExt(resourceId: Int): String { val value = TypedValue() getValue(resourceId, value, true) return value.string.toString().substringAfterLast(".", "")}
val fileExt = resources.getFileExt(R.drawable.ic_check_white_24dp)
Check Drawable == VectorDrawable
val resourceId = R.drawable.ic_check_white_24dpval d = AppCompatResources.getDrawable(context, resourceId)if (d != null) { if (d is VectorDrawableCompat || "android.graphics.drawable.VectorDrawable" == d::class.java.name) { // this is a vector }}