diff --git a/packages/image_picker/CHANGELOG.md b/packages/image_picker/CHANGELOG.md index 145fd4995a8e..a1c108b37368 100644 --- a/packages/image_picker/CHANGELOG.md +++ b/packages/image_picker/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.6.0+13 + +* Bugfix Android: Fix a crash occurs in some scenarios when user picks up image from gallery. + ## 0.6.0+12 * Use class instead of struct for `GIFInfo` in iOS implementation. diff --git a/packages/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/FileUtils.java b/packages/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/FileUtils.java index 85995d890848..15900bea5cc3 100644 --- a/packages/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/FileUtils.java +++ b/packages/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/FileUtils.java @@ -29,7 +29,6 @@ import android.provider.DocumentsContract; import android.provider.MediaStore; import android.text.TextUtils; -import android.webkit.MimeTypeMap; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -141,7 +140,7 @@ private static String getPathFromRemoteUri(final Context context, final Uri uri) OutputStream outputStream = null; boolean success = false; try { - String extension = getImageExtension(context, uri); + String extension = getImageExtension(uri); inputStream = context.getContentResolver().openInputStream(uri); file = File.createTempFile("image_picker", extension, context.getCacheDir()); outputStream = new FileOutputStream(file); @@ -168,31 +167,23 @@ private static String getPathFromRemoteUri(final Context context, final Uri uri) } /** @return extension of image with dot, or default .jpg if it none. */ - private static String getImageExtension(Context context, Uri uriImage) { + private static String getImageExtension(Uri uriImage) { String extension = null; - Cursor cursor = null; try { - cursor = - context - .getContentResolver() - .query(uriImage, new String[] {MediaStore.MediaColumns.MIME_TYPE}, null, null, null); - - if (cursor != null && cursor.moveToNext()) { - String mimeType = cursor.getString(0); - - extension = MimeTypeMap.getSingleton().getExtensionFromMimeType(mimeType); - } - } finally { - if (cursor != null) { - cursor.close(); + String imagePath = uriImage.getPath(); + if (imagePath != null && imagePath.lastIndexOf(".") != -1) { + extension = imagePath.substring(imagePath.lastIndexOf(".") + 1); } + } catch (Exception e) { + extension = null; } - if (extension == null) { + if (extension == null || extension.isEmpty()) { //default extension for matches the previous behavior of the plugin extension = "jpg"; } + return "." + extension; } diff --git a/packages/image_picker/pubspec.yaml b/packages/image_picker/pubspec.yaml index 4d4027156d91..c0c5b7d2a3b2 100755 --- a/packages/image_picker/pubspec.yaml +++ b/packages/image_picker/pubspec.yaml @@ -5,7 +5,7 @@ authors: - Flutter Team - Rhodes Davis Jr. homepage: https://github.com/flutter/plugins/tree/master/packages/image_picker -version: 0.6.0+12 +version: 0.6.0+13 flutter: plugin: