Created
June 28, 2021 06:52
-
-
Save siscofran999/8624a61717514daa3c3096054ed5583c to your computer and use it in GitHub Desktop.
getPath from uri
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun getPath(context: Context, uri: Uri?): String? { | |
var cursor: Cursor? = null | |
return try { | |
val proj = arrayOf(MediaStore.Images.Media.DATA) | |
cursor = uri?.let { context.contentResolver.query(it, proj, null, null, null) } | |
val column_index = cursor!!.getColumnIndexOrThrow(MediaStore.Images.Media.DATA) | |
cursor.moveToFirst() | |
cursor.getString(column_index) | |
} catch (e: Exception) { | |
loge("getRealPathFromURI Exception : $e") | |
"" | |
} finally { | |
cursor?.close() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment