handle cases when column _data does not exist

This commit is contained in:
tibbi 2017-01-04 21:32:34 +01:00
parent 3d089db697
commit c7dd7b7e2e

View file

@ -13,14 +13,15 @@ fun Context.getRealPathFromURI(uri: Uri): String? {
try { try {
val projection = arrayOf(MediaStore.Images.Media.DATA) val projection = arrayOf(MediaStore.Images.Media.DATA)
cursor = contentResolver.query(uri, projection, null, null, null) 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) val index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA)
return cursor.getString(index) return cursor.getString(index)
} }
return null } catch (e: IllegalArgumentException) {
} finally { } finally {
cursor?.close() cursor?.close()
} }
return null
} }
fun Context.getHumanizedFilename(path: String): String { fun Context.getHumanizedFilename(path: String): String {