mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-28 18:03:14 +08:00
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:
@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user