I wrote an plugin to access the ExternalStorageDirectory on Android via Dart.
android specific code for the plugin:
@Override
public void onMethodCall(MethodCall call, Result result) {
if (call.method.equals("getUserDataDirectory")) {
String path = Environment.getExternalStorageDirectory().getAbsolutePath();
result.success(path);
} else {
result.notImplemented();
}
}
The returned path is correct storage/emulated/0
. But now if i try to iterate throw the directory i get an Permission denied.
error.log
[ERROR:topaz/lib/tonic/logging/dart_error.cc(16)] Unhandled exception:
E/flutter ( 3381): FileSystemException: Directory listing failed, path = '/storage/emulated/0/' (OS Error: Permission denied, errno = 13)
E/flutter ( 3381): #0 _Directory._fillWithDirectoryListing (dart:io-patch/directory_patch.dart:32)
E/flutter ( 3381): #1 _Directory.listSync (directory_impl.dart:214)
E/flutter ( 3381): #2 _MyAppState.initPathRequest (/data/user/0/com.yourcompany.userdatadirectoryexample/cache/exampleIAKNFP/example/lib/main.dart:34:25)
main.dart
path = await Userdatadirectory.getUserDataDirectory;
var dir = new Directory(path);
List contents = dir.listSync();
for (var fileOrDir in contents) {
print(fileOrDir.path);
}
my example/android/app/src/AndroidManifest.xml
contains these additional premissions:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
What is the problem here?