Flutter-permission-handler: Unable to open files from storage

Created on 14 Jan 2020  路  5Comments  路  Source: Baseflow/flutter-permission-handler

馃悰 Bug Report

Recieving this error when attempting to get a file from storage with the file picker plugin.

FileSystemException: Cannot open file, path = '/storage/emulated/0/Download/my-file.xml' (OS Error: Permission denied, errno = 13), error

This only seems to happen on android 10.

Doctor summary (to see all details, run flutter doctor -v):
[鈭歖 Flutter (Channel stable, v1.9.1+hotfix.6, on Microsoft Windows [Version 10.0.18362.535], locale en-GB)
[鈭歖 Android toolchain - develop for Android devices (Android SDK version 29.0.2)
[鈭歖 Android Studio (version 3.5)
[鈭歖 VS Code (version 1.41.1)
[鈭歖 VS Code, 64-bit edition (version 1.41.1)
[鈭歖 Connected device (2 available)

Reproduction steps

import 'package:file_picker/file_picker.dart';
try { File file = await FilePicker.getFile(type: FileType.CUSTOM, fileExtension: 'xml'); if (file != null) { File newFile = await file.copy('${(await getApplicationDocumentsDirectory()).path}/${path.basename(file.path)}'); question.setFile= newFile; } } on PlatformException catch (e) { print("Unsupported operation" + e.toString()); }

try { File file = await FilePicker.getFile(type: FileType.CUSTOM, fileExtension: 'xml'); if (file != null) { String filePath = '${(await getApplicationDocumentsDirectory()).path}/${path.basename(file.path)}'; File newFile = File(filePath); question.setFile= await newFile.writeAsBytes(await file.readAsBytes()); } } on PlatformException catch (e) { print("Unsupported operation" + e.toString()); }

Version: 4.0.0

Platform:

  • [ ] :iphone: iOS
  • [x] :robot: Android
android triage

Most helpful comment

Hi @Rossdex, I have been researching this a little bit and seems like this is not really an issue about user consent (which is what the permission_handler plugin is all about), but a problem with actual data access permissions to the location on disk.

I haven't read all the details yet, but there seems to be something with the file_picker plugin and Android 10. Can you try adding the following attribute to the <application> element in your AndroidManifest.xml file:

android:requestLegacyExternalStorage="true"

More information can also be found here: https://github.com/miguelpruivo/flutter_file_picker/issues/169

All 5 comments

@Rossdex, have you tried updating to version 4.1.0? This version has support for the ACCESS_MEDIA_LOCATION permission for Android >= 10.

For more details have a look at: https://github.com/Baseflow/flutter-permission-handler/pull/185

Hi @mvanbeusekom, I've upgraded your package as suggested and I still have the bug.

I did notice that the ACCESS_MEDIA_LOCATION permission seems to be specific to the users geographic location data on media. E.g. where they were when they took a photo etc.

Hi @Rossdex, I have been researching this a little bit and seems like this is not really an issue about user consent (which is what the permission_handler plugin is all about), but a problem with actual data access permissions to the location on disk.

I haven't read all the details yet, but there seems to be something with the file_picker plugin and Android 10. Can you try adding the following attribute to the <application> element in your AndroidManifest.xml file:

android:requestLegacyExternalStorage="true"

More information can also be found here: https://github.com/miguelpruivo/flutter_file_picker/issues/169

Great! Thank you, that has fixed it on both my Emulator and Devices.

android:requestLegacyExternalStorage="true"

But this should only be used as a temporary fix to avoid scoped storage. I think it would be great if the plugin can provide methods to request scoped storage. @mvanbeusekom

Was this page helpful?
0 / 5 - 0 ratings