crashfix at getRealPathFromURI

This commit is contained in:
tibbi 2016-11-14 18:22:42 +01:00
parent 02f855a30d
commit c524044d11

View file

@ -10,9 +10,11 @@ fun Context.getRealPathFromURI(uri: Uri): String? {
try {
val projection = arrayOf(MediaStore.Images.Media.DATA)
cursor = contentResolver.query(uri, projection, null, null, null)
val index = cursor!!.getColumnIndexOrThrow(MediaStore.Images.Media.DATA)
cursor.moveToFirst()
if (cursor != null && cursor.moveToFirst()) {
val index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA)
return cursor.getString(index)
}
return null
} finally {
cursor?.close()
}