无法从光标获取图库图像路径

时间:2020-03-08 11:21:34

标签: android android-image android-gallery android-cursor

我正在使用光标来获取从画廊中选择的图像的路径,但是我从这里得到的是空值,

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()
        }
    }
}

我从意图数据中获取uri,并且在函数中它不为null,但查询仍然找不到任何路径。 uri像这样content://com.android.providers.media.documents/document/image%3A121080

来到这里

0 个答案:

没有答案