catch exceptions thrown during media obtaining

This commit is contained in:
tibbi 2017-05-21 09:17:52 +02:00
parent 52126c4d8f
commit b564da6b91

View file

@ -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()