0

I am using cursor to get the path of image chosen from the gallery, but I am getting null from here,

object ImageUtil {
    fun getGalleryImagePath(context: Context, uri: Uri): String? {
        var cursor: Cursor? = null

        return try {
            val projection = arrayOf(MediaStore.Images.Media.DATA)
            cursor = context.contentResolver.query(uri!!, projection, null, null, null)
            val column_index = cursor!!.getColumnIndexOrThrow(projection[0])
            cursor.moveToFirst()
            cursor.getString(column_index)
        } finally {
            cursor?.close()
        }
    }
}

I am getting the uri from intent data and in the function it is not null, still the query cannot find any path. The uri is coming here like this content://com.android.providers.media.documents/document/image%3A121080

SuvodipMondal
  • 87
  • 1
  • 8

0 Answers0