Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save siscofran999/8624a61717514daa3c3096054ed5583c to your computer and use it in GitHub Desktop.
Save siscofran999/8624a61717514daa3c3096054ed5583c to your computer and use it in GitHub Desktop.
getPath from uri
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