From c7dd7b7e2eaf0021031f4441afe6641db47bbd51 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 4 Jan 2017 21:32:34 +0100 Subject: [PATCH] handle cases when column _data does not exist --- .../com/simplemobiletools/gallery/extensions/context.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt index b7e39d603..f6e33dc14 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt @@ -13,14 +13,15 @@ fun Context.getRealPathFromURI(uri: Uri): String? { try { val projection = arrayOf(MediaStore.Images.Media.DATA) cursor = contentResolver.query(uri, projection, null, null, null) - if (cursor != null && cursor.moveToFirst()) { + if (cursor?.moveToFirst() == true) { val index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA) return cursor.getString(index) } - return null + } catch (e: IllegalArgumentException) { } finally { cursor?.close() } + return null } fun Context.getHumanizedFilename(path: String): String {