From 103968710cc5688ea53a249ecd5ac83260e760c2 Mon Sep 17 00:00:00 2001 From: dankito Date: Thu, 19 Nov 2020 22:25:18 +0100 Subject: [PATCH] Tried to fix bug that due to scoped storage on Android 10 and above no files are displayed in AndroidFileChooserDialog at least on Android 10. Set target SDK version therefore to Android 10 (for details see https://developer.android.com/training/data-storage/use-cases#opt-out-scoped-storage). TODO: remove debug log output after fixing the bug completely --- build.gradle | 6 +++--- ui/BankingAndroidApp/src/main/AndroidManifest.xml | 5 +++++ .../views/MainActivityFloatingActionMenuButton.kt | 15 +++++++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index 37df00d5..5e831210 100644 --- a/build.gradle +++ b/build.gradle @@ -43,13 +43,13 @@ ext { /* Android */ - androidCompileSdkVersion = 30 + androidCompileSdkVersion = 29 - androidBuildToolsVersion = "30.0.2" + androidBuildToolsVersion = "29.0.2" androidMinSdkVersion = 21 // TODO: fix SSLv3 / TLS and set back to 16 - androidTargetSdkVersion = 30 + androidTargetSdkVersion = 29 fileChooserDialogVersion = "1.3.0-androidx" diff --git a/ui/BankingAndroidApp/src/main/AndroidManifest.xml b/ui/BankingAndroidApp/src/main/AndroidManifest.xml index e8552e3c..0a13382e 100644 --- a/ui/BankingAndroidApp/src/main/AndroidManifest.xml +++ b/ui/BankingAndroidApp/src/main/AndroidManifest.xml @@ -10,6 +10,10 @@ + + + + @@ -25,6 +29,7 @@ android:supportsRtl="true" android:hardwareAccelerated="true" android:theme="@style/AppTheme" + android:requestLegacyExternalStorage="true" > + // TODO: remove again as soon as bug that no files are displayed in FileChooserDialog (on Android 10 and higher?) is fixed + log.info("config.initialDirectory = ${presenter.appSettings.lastSelectedOpenPdfFolder}, Environment.getExternalStorageDirectory() = ${Environment.getExternalStorageDirectory()}, " + + "Downloads dir = ${Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)}") + log.info("External storage files: ${Environment.getExternalStorageDirectory()?.listFiles()?.map { it.name }}") + log.info("getExternalStorageState() = ${Environment.getExternalStorageState()}, isExternalStorageEmulated() = ${Environment.isExternalStorageEmulated()}, " + + "isExternalStorageRemovable() = ${Environment.isExternalStorageRemovable()}") + val config = FileChooserDialogConfig(listOf("*.pdf"), presenter.appSettings.lastSelectedOpenPdfFolder.toFile()) FileChooserDialog().showOpenSingleFileDialog(activity, permissionsService, config) { _, selectedFile ->