From 1db016235cf7448980b1922d34db00de12c079f2 Mon Sep 17 00:00:00 2001 From: Alex Babich Date: Mon, 1 Jul 2024 10:42:38 +0300 Subject: [PATCH 1/7] - Added namespace --- android/build.gradle | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/android/build.gradle b/android/build.gradle index 8ad2194..5224ca6 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -28,6 +28,11 @@ apply plugin: 'kotlin-android' android { compileSdkVersion 33 + if (project.android.hasProperty('namespace')) { + namespace 'io.alexrintt.sharedstorage' + } + + sourceSets { main.java.srcDirs += 'src/main/kotlin' } From 355ba2a65b4212fa765b0ca110fe9ea8e5cf93e2 Mon Sep 17 00:00:00 2001 From: Alex Babich Date: Mon, 1 Jul 2024 11:00:22 +0300 Subject: [PATCH 2/7] - Fixed error in takeIf condition --- lib/src/common/functional_extender.dart | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/src/common/functional_extender.dart b/lib/src/common/functional_extender.dart index 7e0bd65..c9abffc 100644 --- a/lib/src/common/functional_extender.dart +++ b/lib/src/common/functional_extender.dart @@ -25,7 +25,13 @@ extension FunctionalExtender on T? { T? takeIf(bool Function(T) f) { final T? self = this; - return self != null && f(self) ? self : null; + if (self == null) return null; + + if (f(self)) { + return self; + } else { + return null; + } } } From 8784c39b909324df8913dd30fa416b8a50d55f49 Mon Sep 17 00:00:00 2001 From: Alex Babich Date: Mon, 1 Jul 2024 12:54:06 +0300 Subject: [PATCH 3/7] - Added Java compile version --- android/build.gradle | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/android/build.gradle b/android/build.gradle index 5224ca6..fc0801d 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -39,6 +39,11 @@ android { defaultConfig { minSdkVersion 19 } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 + } } dependencies { From 9dd54437002c7e0ea44b22dc0e7de50580eaf7f7 Mon Sep 17 00:00:00 2001 From: tajuddin Date: Wed, 7 May 2025 16:35:08 +0800 Subject: [PATCH 4/7] Update build.gradle --- android/build.gradle | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/android/build.gradle b/android/build.gradle index fc0801d..ee7dcd4 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -44,6 +44,11 @@ android { sourceCompatibility JavaVersion.VERSION_17 targetCompatibility JavaVersion.VERSION_17 } + + kotlinOptions { + jvmTarget = "17" // Explicitly match Java's version + } + } dependencies { From 0a828da70c10b8296751b974c328250f7fcb2fbe Mon Sep 17 00:00:00 2001 From: tajuddin Date: Wed, 7 May 2025 16:48:54 +0800 Subject: [PATCH 5/7] Update build.gradle --- android/build.gradle | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index ee7dcd4..7f8e851 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -41,12 +41,12 @@ android { } compileOptions { - sourceCompatibility JavaVersion.VERSION_17 - targetCompatibility JavaVersion.VERSION_17 + sourceCompatibility JavaVersion.VERSION_18 + targetCompatibility JavaVersion.VERSION_18 } kotlinOptions { - jvmTarget = "17" // Explicitly match Java's version + jvmTarget = "18" // Explicitly match Java's version } } From b6d842664abad9c6149782c6c1fa30876b7a4c43 Mon Sep 17 00:00:00 2001 From: tajuddin Date: Wed, 7 May 2025 16:55:49 +0800 Subject: [PATCH 6/7] Update gradle.properties --- android/gradle.properties | 1 + 1 file changed, 1 insertion(+) diff --git a/android/gradle.properties b/android/gradle.properties index 94adc3a..842dce9 100644 --- a/android/gradle.properties +++ b/android/gradle.properties @@ -1,3 +1,4 @@ org.gradle.jvmargs=-Xmx1536M android.useAndroidX=true android.enableJetifier=true +kotlin.jvm.target.validation.mode = IGNORE \ No newline at end of file From 012e22791138958e089f6c1a8d6c4c6943a9f253 Mon Sep 17 00:00:00 2001 From: Oleksandr Babich Date: Thu, 12 Jun 2025 17:45:51 +0300 Subject: [PATCH 7/7] - Added validation of SAF availability. --- .../sharedstorage/deprecated/DocumentFileApi.kt | 13 +++++++++++++ .../lib/StorageAccessFrameworkConstant.kt | 1 + lib/src/saf/saf.dart | 12 ++++++++++++ 3 files changed, 26 insertions(+) diff --git a/android/src/main/kotlin/io/alexrintt/sharedstorage/deprecated/DocumentFileApi.kt b/android/src/main/kotlin/io/alexrintt/sharedstorage/deprecated/DocumentFileApi.kt index fd17f6f..e29cd11 100644 --- a/android/src/main/kotlin/io/alexrintt/sharedstorage/deprecated/DocumentFileApi.kt +++ b/android/src/main/kotlin/io/alexrintt/sharedstorage/deprecated/DocumentFileApi.kt @@ -289,10 +289,23 @@ internal class DocumentFileApi(private val plugin: SharedStoragePlugin) : result.notSupported(CHILD, API_21, mapOf("uri" to uri)) } } + CAN_OPEN_DOCUMENT_TREE -> { + result.success(canOpenDocumentTree()) + } else -> result.notImplemented() } } + private fun canOpenDocumentTree(): Boolean { + return try { + val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) + val activities = plugin.context.packageManager.queryIntentActivities(intent, 0) + activities.isNotEmpty() + } catch (e: Exception) { + false + } + } + @RequiresApi(API_21) private fun openDocument(call: MethodCall, result: MethodChannel.Result) { val initialUri = call.argument("initialUri") diff --git a/android/src/main/kotlin/io/alexrintt/sharedstorage/deprecated/lib/StorageAccessFrameworkConstant.kt b/android/src/main/kotlin/io/alexrintt/sharedstorage/deprecated/lib/StorageAccessFrameworkConstant.kt index 62af0c2..0fa9b62 100644 --- a/android/src/main/kotlin/io/alexrintt/sharedstorage/deprecated/lib/StorageAccessFrameworkConstant.kt +++ b/android/src/main/kotlin/io/alexrintt/sharedstorage/deprecated/lib/StorageAccessFrameworkConstant.kt @@ -39,6 +39,7 @@ const val COPY = "copy" const val LAST_MODIFIED = "lastModified" const val GET_DOCUMENT_THUMBNAIL = "getDocumentThumbnail" const val CHILD = "child" +const val CAN_OPEN_DOCUMENT_TREE = "canOpenDocumentTree" /** * Available DocumentFileHelper Method Channel APIs diff --git a/lib/src/saf/saf.dart b/lib/src/saf/saf.dart index a0dd059..b3c45d3 100644 --- a/lib/src/saf/saf.dart +++ b/lib/src/saf/saf.dart @@ -134,6 +134,18 @@ Future canRead(Uri uri) async => kDocumentFileChannel Future canWrite(Uri uri) async => kDocumentFileChannel .invokeMethod('canWrite', {'uri': '$uri'}); +/// {@template sharedstorage.saf.canOpenDocumentTree} +/// Check if the device supports Storage Access Framework (SAF) and can open document trees. +/// +/// Returns `true` if the device has apps that can handle ACTION_OPEN_DOCUMENT_TREE intents, +/// `false` otherwise. This is useful to determine SAF support before attempting to use +/// document tree operations. +/// +/// [Refer to details](https://developer.android.com/reference/android/content/Intent#ACTION_OPEN_DOCUMENT_TREE). +/// {@endtemplate} +Future canOpenDocumentTree() async => kDocumentFileChannel + .invokeMethod('canOpenDocumentTree'); + /// {@template sharedstorage.saf.getDocumentThumbnail} /// Equivalent to `DocumentsContract.getDocumentThumbnail`. ///