External Storage Android: Check if Dir is writable

And according try to use the new Android 10 Storage APIs. Though they
seem to not give me exactly what I want.
This commit is contained in:
Vishesh Handa
2020-12-27 09:37:54 +01:00
parent 10bf342497
commit fe8a6a88b1

View File

@ -320,6 +320,10 @@ class SettingsListState extends State<SettingsList> {
var extDir = await getExternalStorageDirectory();
Log.i("Ext Dir: $extDir");
if (await _isDirWritable(path) == false) {
path = extDir.path;
}
if (path == null || path.isEmpty) {
settings.storeInternally = true;
settings.storageLocation = "";
@ -519,3 +523,17 @@ class VersionNumberTileState extends State<VersionNumberTile> {
);
}
}
Future<bool> _isDirWritable(String path) async {
var fileName = DateTime.now().millisecondsSinceEpoch.toString();
var file = File(p.join(path, fileName));
try {
await file.writeAsString("test");
await file.delete();
} catch (_) {
return false;
}
return true;
}