diff --git a/build.gradle b/build.gradle index a62e167bd..5ba943679 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ buildscript { propMinSdkVersion = 21 propTargetSdkVersion = propCompileSdkVersion propVersionCode = 1 - propVersionName = '5.24.18' + propVersionName = '5.24.19' kotlin_version = '1.3.71' } diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Context.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Context.kt index 5996c87d5..79df3ea3c 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Context.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Context.kt @@ -306,6 +306,31 @@ fun Context.getMediaContent(path: String, uri: Uri): Uri? { return null } +fun Context.queryCursor( + uri: Uri, + projection: Array, + selection: String? = null, + selectionArgs: Array? = null, + sortOrder: String? = null, + showErrors: Boolean = false, + callback: (cursor: Cursor) -> Unit +) { + try { + val cursor = contentResolver.query(uri, projection, selection, selectionArgs, sortOrder) + cursor?.use { + if (cursor.moveToFirst()) { + do { + callback(cursor) + } while (cursor.moveToNext()) + } + } + } catch (e: Exception) { + if (showErrors) { + showErrorToast(e) + } + } +} + fun Context.getFilenameFromUri(uri: Uri): String { return if (uri.scheme == "file") { File(uri.toString()).name