From fe8a6a88b1e54cda67e3ea8f8cb2adfdf2c7a3d1 Mon Sep 17 00:00:00 2001 From: Vishesh Handa Date: Sun, 27 Dec 2020 09:37:54 +0100 Subject: [PATCH] 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. --- lib/screens/settings_screen.dart | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/screens/settings_screen.dart b/lib/screens/settings_screen.dart index 0c668c76..f636252f 100644 --- a/lib/screens/settings_screen.dart +++ b/lib/screens/settings_screen.dart @@ -320,6 +320,10 @@ class SettingsListState extends State { 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 { ); } } + +Future _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; +}