flutter_file_picker icon indicating copy to clipboard operation
flutter_file_picker copied to clipboard

allowedExtensions does not work on Android 13 physical device

Open pavkoccino opened this issue 9 months ago • 3 comments

Similar issues: https://github.com/miguelpruivo/flutter_file_picker/issues/1679 https://github.com/miguelpruivo/flutter_file_picker/issues/1694

Describe the bug When using allowedExtensions filter different than .jpg/.png (those pop different selection) on Android 13 (not sure about other versions as this Is what I tested) no files can be selected.

My specific case is I want to restrict selection of just .pfx and .p12 files.

Right now my workaround is to allow all files (don't pass any allowedExtensions) and later check the extension myself.

Platform

  • [ ❌] Android (does not work)
    • Android 13 physical device - not working (see the screenshot, the files are greyed out), the device I am testing on is SM G780F (mobile) (see the flutter doctor -v)
    • Android 13 emulator - works - this is weird
    • Android 14 emulator - works
  • [✅ ] iOS (works)

How are you picking?

    final FilePickerResult? result = await FilePicker.platform.pickFiles(
      allowedExtensions: ['pfx', 'p12'],
      type: FileType.custom,
    );

Details to reproduce the issue

  • Have some pfx or p12 file on the device (cannot attach it unfortunately, you will need to find some, or create one for testing). Maybe simply creating test.pfx file on the device could be enough.
  • Try to pick it with the command seen above.
  • You will be blocked from selecting it

Error Log No error, just blocking the files from picking.

Screenshots and/or video

Flutter Version details

[!] Flutter (Channel [user-branch], 3.24.5, on macOS 15.3 24D60 darwin-arm64,
    locale cs-CZ)
    ! Flutter version 3.24.5 on channel [user-branch] at
      /Users/pavelpek/development/flutter
      Currently on an unknown channel. Run `flutter channel` to switch to an
      official channel.
      If that doesn't fix the issue, reinstall Flutter by following
      instructions at https://flutter.dev/setup.
    ! Upstream repository unknown source is not a standard remote.
      Set environment variable "FLUTTER_GIT_URL" to unknown source to dismiss
      this error.
    • Framework revision dec2ee5c1f (3 months ago), 2024-11-13 11:13:06 -0800
    • Engine revision a18df97ca5
    • Dart version 3.5.4
    • DevTools version 2.37.3
    • If those were intentional, you can disregard the above warnings; however
      it is recommended to use "git" directly to perform update checks and
      upgrades.

[✓] Android toolchain - develop for Android devices (Android SDK version
    35.0.1)
    • Android SDK at /Users/pavelpek/Library/Android/sdk
    • Platform android-35, build-tools 35.0.1
    • Java binary at:
      /Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home/bin/java
    • Java version Java(TM) SE Runtime Environment (build 17.0.9+11-LTS-201)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 16.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 16C5032a
    • CocoaPods version 1.16.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2024.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 21.0.4+-12422083-b607.1)

[✓] VS Code (version 1.97.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.104.0

[✓] Connected device (6 available)
    • SM G780F (mobile)               • RF8NA1A4GQV               •
      android-arm64  • Android 13 (API 33)
    • sdk gphone64 arm64 (mobile)     • emulator-5554             •
      android-arm64  • Android 14 (API 34) (emulator)
    • Pavel - iPhone (mobile)         • 00008101-000D2CA43A51001E • ios
      • iOS 18.3.1 22D72
    • macOS (desktop)                 • macos                     •
      darwin-arm64   • macOS 15.3 24D60 darwin-arm64
    • Mac Designed for iPad (desktop) • mac-designed-for-ipad     • darwin
      • macOS 15.3 24D60 darwin-arm64
    • Chrome (web)                    • chrome                    •
      web-javascript • Google Chrome 133.0.6943.127

[✓] Network resources
    • All expected network resources are available.

Additional context I believe it used to work on this device when I was implementing this feature while ago, could be OS related somehow (some update or whatever)?

pavkoccino avatar Feb 24 '25 12:02 pavkoccino

I think our usage of Intent.EXTRA_MIME_TYPES could be broken then, there are two different styles of setting the mime types for the intent. Also the type of the intent is not set correctly it seems.

Note: Your intent must specify a MIME type and must declare the [CATEGORY_OPENABLE](https://developer.android.com/reference/android/content/Intent#CATEGORY_OPENABLE) category. If appropriate, you can specify more than one MIME type by adding an array of MIME types with the [EXTRA_MIME_TYPES](https://developer.android.com/reference/android/content/Intent#EXTRA_MIME_TYPES) extra—if you do so, you must set the primary MIME type in [setType()](https://developer.android.com/reference/android/content/Intent#setType(java.lang.String)) to "*/*".

navaronbracke avatar Feb 27 '25 16:02 navaronbracke

In my case, Android 15 physical device, all files are shown, ignoring allowedExtensions. FilePicker.platform.pickFiles(type: FileType.custom, allowedExtensions: ['csv'], withData: true) On Web, this works fine.

ma-ruz avatar Apr 16 '25 10:04 ma-ruz

I have tested on Android 14 physical device and all files are shown as @ma-ruz mentioned

obenkucuk avatar Apr 16 '25 19:04 obenkucuk