Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/image_picker/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/image_picker/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ authors:
- Flutter Team <flutter-dev@googlegroups.com>
- Rhodes Davis Jr. <rody.davis.jr@gmail.com>
homepage: https://github.com/flutter/plugins/tree/master/packages/image_picker
version: 0.6.0+12
version: 0.6.0+13

flutter:
plugin:
Expand Down