catch exceptions thrown during media obtaining
This commit is contained in:
parent
52126c4d8f
commit
b564da6b91
1 changed files with 44 additions and 36 deletions
|
@ -139,6 +139,7 @@ fun Context.getFilesFrom(curPath: String, isPickImage: Boolean, isPickVideo: Boo
|
|||
val selectionArgs = if (curPath.isEmpty()) null else arrayOf("$curPath/%", "$curPath/%/%")
|
||||
|
||||
val cur = contentResolver.query(uri, projection, selection, selectionArgs, getSortingForFolder(curPath))
|
||||
try {
|
||||
if (cur.moveToFirst()) {
|
||||
var filename: String
|
||||
var path: String
|
||||
|
@ -148,7 +149,9 @@ fun Context.getFilesFrom(curPath: String, isPickImage: Boolean, isPickVideo: Boo
|
|||
var isImage: Boolean
|
||||
var isVideo: Boolean
|
||||
|
||||
|
||||
do {
|
||||
try {
|
||||
path = cur.getStringValue(MediaStore.Images.Media.DATA)
|
||||
size = cur.getLongValue(MediaStore.Images.Media.SIZE)
|
||||
if (size == 0L) {
|
||||
|
@ -183,9 +186,14 @@ fun Context.getFilesFrom(curPath: String, isPickImage: Boolean, isPickVideo: Boo
|
|||
|
||||
val medium = Medium(filename, path, isVideo, dateModified, dateTaken, size)
|
||||
curMedia.add(medium)
|
||||
} catch (e: Exception) {
|
||||
continue
|
||||
}
|
||||
} while (cur.moveToNext())
|
||||
}
|
||||
} finally {
|
||||
cur.close()
|
||||
}
|
||||
|
||||
Medium.sorting = config.getFileSorting(curPath)
|
||||
curMedia.sort()
|
||||
|
|
Loading…
Reference in a new issue