From 0a98fd053605aaf0276dee8fbb19e8ed80e6fa05 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 23 Apr 2020 23:02:38 +0200 Subject: [PATCH] catch exceptions thrown at getting file date taken --- .../gallery/pro/extensions/Context.kt | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt index b205d09c9..239deeb9b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt @@ -894,16 +894,14 @@ fun Context.getFileDateTaken(path: String): Long { val selection = "${Images.Media.DATA} = ?" val selectionArgs = arrayOf(path) - val cursor = contentResolver.query(uri, projection, selection, selectionArgs, null) - cursor?.use { - if (cursor.moveToFirst()) { - do { - try { - return cursor.getLongValue(Images.Media.DATE_TAKEN) - } catch (ignored: Exception) { - } - } while (cursor.moveToNext()) + try { + val cursor = contentResolver.query(uri, projection, selection, selectionArgs, null) + cursor?.use { + if (cursor.moveToFirst()) { + return cursor.getLongValue(Images.Media.DATE_TAKEN) + } } + } catch (ignored: Exception) { } return 0L