From c7e5caa68eb97db400160a71082cdde1a183965f Mon Sep 17 00:00:00 2001 From: Anish Kumar Date: Thu, 22 Jan 2026 16:44:21 +0530 Subject: [PATCH] Enable native file picker support on Android 9 and older --- doc/classes/DisplayServer.xml | 2 +- doc/classes/FileDialog.xml | 2 +- .../lib/src/main/java/org/godotengine/godot/Godot.kt | 10 +++------- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/doc/classes/DisplayServer.xml b/doc/classes/DisplayServer.xml index b37b830a44c..d568c96626a 100644 --- a/doc/classes/DisplayServer.xml +++ b/doc/classes/DisplayServer.xml @@ -785,7 +785,7 @@ Displays OS native dialog for selecting files or directories in the file system. Each filter string in the [param filters] array should be formatted like this: [code]*.png,*.jpg,*.jpeg;Image Files;image/png,image/jpeg[/code]. The description text of the filter is optional and can be omitted. It is recommended to set both file extension and MIME type. See also [member FileDialog.filters]. Callbacks have the following arguments: [code]status: bool, selected_paths: PackedStringArray, selected_filter_index: int[/code]. [b]On Android,[/b] the third callback argument ([code]selected_filter_index[/code]) is always [code]0[/code]. - [b]Note:[/b] This method is implemented if the display server has the [constant FEATURE_NATIVE_DIALOG_FILE] feature. Supported platforms include Linux (X11/Wayland), Windows, macOS, and Android (API level 29+). + [b]Note:[/b] This method is implemented if the display server has the [constant FEATURE_NATIVE_DIALOG_FILE] feature. Supported platforms include Linux (X11/Wayland), Windows, macOS, and Android. [b]Note:[/b] [param current_directory] might be ignored. [b]Note:[/b] Embedded file dialogs and Windows file dialogs support only file extensions, while Android, Linux, and macOS file dialogs also support MIME types. [b]Note:[/b] On Android and Linux, [param show_hidden] is ignored. diff --git a/doc/classes/FileDialog.xml b/doc/classes/FileDialog.xml index f8b783b37fb..20cc433c528 100644 --- a/doc/classes/FileDialog.xml +++ b/doc/classes/FileDialog.xml @@ -276,7 +276,7 @@ If [code]true[/code], and if supported by the current [DisplayServer], OS native dialog will be used instead of custom one. - [b]Note:[/b] On Android, it is only supported for Android 10+ devices and when using [constant ACCESS_FILESYSTEM]. For access mode [constant ACCESS_RESOURCES] and [constant ACCESS_USERDATA], the system will fall back to custom FileDialog. + [b]Note:[/b] On Android, it is only supported when using [constant ACCESS_FILESYSTEM]. For access mode [constant ACCESS_RESOURCES] and [constant ACCESS_USERDATA], the system will fall back to custom FileDialog. [b]Note:[/b] On Linux and macOS, sandboxed apps always use native dialogs to access the host file system. [b]Note:[/b] On macOS, sandboxed apps will save security-scoped bookmarks to retain access to the opened folders across multiple sessions. Use [method OS.get_granted_permissions] to get a list of saved bookmarks. [b]Note:[/b] Native dialogs are isolated from the base process, file dialog properties can't be modified once the dialog is shown. diff --git a/platform/android/java/lib/src/main/java/org/godotengine/godot/Godot.kt b/platform/android/java/lib/src/main/java/org/godotengine/godot/Godot.kt index a1bfbcb9a21..f467d2c85ca 100644 --- a/platform/android/java/lib/src/main/java/org/godotengine/godot/Godot.kt +++ b/platform/android/java/lib/src/main/java/org/godotengine/godot/Godot.kt @@ -790,10 +790,8 @@ class Godot private constructor(val context: Context) { for (plugin in pluginRegistry.allPlugins) { plugin.onMainActivityResult(requestCode, resultCode, data) } - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { - runOnRenderThread { - FilePicker.handleActivityResult(context, requestCode, resultCode, data) - } + runOnRenderThread { + FilePicker.handleActivityResult(context, requestCode, resultCode, data) } } @@ -1041,9 +1039,7 @@ class Godot private constructor(val context: Context) { @Keep private fun showFilePicker(currentDirectory: String, filename: String, fileMode: Int, filters: Array) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { - FilePicker.showFilePicker(context, getActivity(), currentDirectory, filename, fileMode, filters) - } + FilePicker.showFilePicker(context, getActivity(), currentDirectory, filename, fileMode, filters) } /**