Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,27 @@ apply plugin: 'kotlin-android'
android {
compileSdkVersion 33

if (project.android.hasProperty('namespace')) {
namespace 'io.alexrintt.sharedstorage'
}


sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
minSdkVersion 19
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_18
targetCompatibility JavaVersion.VERSION_18
}

kotlinOptions {
jvmTarget = "18" // Explicitly match Java's version
}

}

dependencies {
Expand Down
1 change: 1 addition & 0 deletions android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
kotlin.jvm.target.validation.mode = IGNORE
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>("initialUri")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion lib/src/common/functional_extender.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ extension FunctionalExtender<T> 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;
}
}
}

Expand Down
12 changes: 12 additions & 0 deletions lib/src/saf/saf.dart
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,18 @@ Future<bool?> canRead(Uri uri) async => kDocumentFileChannel
Future<bool?> canWrite(Uri uri) async => kDocumentFileChannel
.invokeMethod<bool>('canWrite', <String, String>{'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<bool?> canOpenDocumentTree() async => kDocumentFileChannel
.invokeMethod<bool>('canOpenDocumentTree');

/// {@template sharedstorage.saf.getDocumentThumbnail}
/// Equivalent to `DocumentsContract.getDocumentThumbnail`.
///
Expand Down