From d7cbe403950e26b623cae059428fcd02373c2f20 Mon Sep 17 00:00:00 2001 From: Iulian Ciorascu Date: Thu, 9 Feb 2023 16:14:50 +0100 Subject: [PATCH] Download to the public Downloads folder. Removed ununsed permissions. --- android/app/src/debug/AndroidManifest.xml | 10 +++++++--- android/app/src/main/AndroidManifest.xml | 7 ++++--- lib/core/service/file_service.dart | 13 ++++++++++--- .../view/widgets/document_download_button.dart | 9 +++++++++ 4 files changed, 30 insertions(+), 9 deletions(-) diff --git a/android/app/src/debug/AndroidManifest.xml b/android/app/src/debug/AndroidManifest.xml index 3c22aad..251e581 100644 --- a/android/app/src/debug/AndroidManifest.xml +++ b/android/app/src/debug/AndroidManifest.xml @@ -1,11 +1,15 @@ + - - - + + + diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 8b89b7a..9ba6f3a 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -2,7 +2,8 @@ package="com.example.paperless_mobile"> + android:icon="@mipmap/launcher_icon" + android:requestLegacyExternalStorage="true"> - + diff --git a/lib/core/service/file_service.dart b/lib/core/service/file_service.dart index ccf2de6..103db3b 100644 --- a/lib/core/service/file_service.dart +++ b/lib/core/service/file_service.dart @@ -58,9 +58,16 @@ class FileService { static Future get downloadsDirectory async { if (Platform.isAndroid) { - return (await getExternalStorageDirectories( - type: StorageDirectory.downloads))! - .first; + Directory? directory; + directory = Directory('/storage/emulated/0/Download'); + // Try the default global folder, if it exists + if (!await directory.exists()) { + directory = (await getExternalStorageDirectories( + type: StorageDirectory.downloads, + ))! + .first; + } + return directory; } else if (Platform.isIOS) { return getApplicationDocumentsDirectory(); } else { diff --git a/lib/features/document_details/view/widgets/document_download_button.dart b/lib/features/document_details/view/widgets/document_download_button.dart index ccaf894..0e6845d 100644 --- a/lib/features/document_details/view/widgets/document_download_button.dart +++ b/lib/features/document_details/view/widgets/document_download_button.dart @@ -6,8 +6,10 @@ import 'package:paperless_mobile/core/service/file_service.dart'; import 'package:paperless_mobile/extensions/flutter_extensions.dart'; import 'package:paperless_mobile/generated/l10n.dart'; import 'package:paperless_mobile/helpers/message_helpers.dart'; +import 'package:paperless_mobile/helpers/permission_helpers.dart'; import 'package:paperless_mobile/constants.dart'; import 'package:provider/provider.dart'; +import 'package:permission_handler/permission_handler.dart'; class DocumentDownloadButton extends StatefulWidget { final DocumentModel? document; @@ -47,6 +49,13 @@ class _DocumentDownloadButtonState extends State { context, "This feature is currently only supported on Android!"); return; } + if (true) { + // should check for android versions < 30 + final isGranted = await askForPermission(Permission.storage); + if (!isGranted) { + return; + } + } setState(() => _isDownloadPending = true); final service = context.read(); try {