From 9196eddccde17764d6d676593098e40f83d447c3 Mon Sep 17 00:00:00 2001 From: Wenqi Li Date: Sat, 22 Aug 2020 14:12:11 +0800 Subject: [PATCH] wrap contentResolver.loadThumbnail method in try/catch, when FileNotFoundException threw return null instead. --- .../morbit/photogallery/PhotoGalleryPlugin.kt | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/android/src/main/kotlin/com/morbit/photogallery/PhotoGalleryPlugin.kt b/android/src/main/kotlin/com/morbit/photogallery/PhotoGalleryPlugin.kt index 038cd65..596917d 100644 --- a/android/src/main/kotlin/com/morbit/photogallery/PhotoGalleryPlugin.kt +++ b/android/src/main/kotlin/com/morbit/photogallery/PhotoGalleryPlugin.kt @@ -402,11 +402,15 @@ class PhotoGalleryPlugin : FlutterPlugin, MethodCallHandler { val bitmap: Bitmap? = this.context?.run { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { - this.contentResolver.loadThumbnail( - ContentUris.withAppendedId(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, mediumId.toLong()), - Size(width ?: 72, height ?: 72), + try { + this.contentResolver.loadThumbnail( + ContentUris.withAppendedId(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, mediumId.toLong()), + Size(width ?: 72, height ?: 72), + null + ) + } catch (e: Exception) { null - ) + } } else { MediaStore.Images.Thumbnails.getThumbnail( this.contentResolver, mediumId.toLong(), @@ -430,11 +434,15 @@ class PhotoGalleryPlugin : FlutterPlugin, MethodCallHandler { val bitmap: Bitmap? = this.context?.run { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { - this.contentResolver.loadThumbnail( - ContentUris.withAppendedId(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, mediumId.toLong()), - Size(width ?: 72, height ?: 72), + try { + this.contentResolver.loadThumbnail( + ContentUris.withAppendedId(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, mediumId.toLong()), + Size(width ?: 72, height ?: 72), + null + ) + } catch (e: Exception) { null - ) + } } else { MediaStore.Video.Thumbnails.getThumbnail( this.contentResolver, mediumId.toLong(),