Starting from API 29 (Android 10), Scoped Storage was introduced. Earlier I was able to directly create a sharable file and write in it using this in Flutter:
File f = File("/storage/emulated/0/MyApp/myFile.txt");
await f.writeAsString(contents);
But with privacy changes now it seems impossible to do the same in Android 10 even after I give the Storage permission.
According to documentation,
Move any shared non-media files to an app-dedicated subdirectory of the Downloads/ directory.
My questions are:
- Can I still create a file in
/storage/emulated/0/MyApp/myFile.txt
, if yes how? - If not, then can I create a file in
/storage/emulated/0/Download/MyApp/myFile.txt
directly from Flutter without Platform code? - If I need to use platform specific code, is using file picker the only option for txt file?
Also I don't want to use android:requestLegacyExternalStorage="true"
because then my app won't work for Android 11.
Unfortunately it does not seem this has been implemented in Flutter yet to account for the new scoped storage changes. There is an open issue on GitHub: https://github.com/flutter/flutter/issues/35783