From a1878c8816bf937e22caec40af5e2156621a64ed Mon Sep 17 00:00:00 2001 From: Tejas Mehta Date: Sat, 27 Mar 2021 01:35:53 -0400 Subject: [PATCH] check if the type is an image and utilize the MediaStore Opener (which goes through the gallery) instead --- CHANGELOG.md | 4 ++++ .../mr/flutter/plugin/filepicker/FilePickerDelegate.java | 8 ++++++-- pubspec.yaml | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ae1b3a1..83471c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 3.0.1 +#### Android +- Use MediaStore Opener (which goes through the gallery) instead of default explorer. (Thank you @tmthecoder). + ## 3.0.0 Adds null safety support ([#510](https://github.com/miguelpruivo/flutter_file_picker/issues/510)). ## 2.1.7 diff --git a/android/src/main/java/com/mr/flutter/plugin/filepicker/FilePickerDelegate.java b/android/src/main/java/com/mr/flutter/plugin/filepicker/FilePickerDelegate.java index c0d5df3..a78af7c 100644 --- a/android/src/main/java/com/mr/flutter/plugin/filepicker/FilePickerDelegate.java +++ b/android/src/main/java/com/mr/flutter/plugin/filepicker/FilePickerDelegate.java @@ -197,13 +197,17 @@ public class FilePickerDelegate implements PluginRegistry.ActivityResultListener if (type.equals("dir")) { intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE); } else { - intent = new Intent(Intent.ACTION_GET_CONTENT); + if (type.equals("image/*")) { + intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); + } else { + intent = new Intent(Intent.ACTION_GET_CONTENT); + intent.addCategory(Intent.CATEGORY_OPENABLE); + } final Uri uri = Uri.parse(Environment.getExternalStorageDirectory().getPath() + File.separator); Log.d(TAG, "Selected type " + type); intent.setDataAndType(uri, this.type); intent.setType(this.type); intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, this.isMultipleSelection); - intent.addCategory(Intent.CATEGORY_OPENABLE); if (type.contains(",")) { allowedExtensions = type.split(","); diff --git a/pubspec.yaml b/pubspec.yaml index 18f6d24..07eb50a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: file_picker description: A package that allows you to use a native file explorer to pick single or multiple absolute file paths, with extension filtering support. homepage: https://github.com/miguelpruivo/plugins_flutter_file_picker -version: 3.0.0 +version: 3.0.1 dependencies: flutter: