-
-
Notifications
You must be signed in to change notification settings - Fork 21.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Android] Implement native file picker support #98350
[Android] Implement native file picker support #98350
Conversation
603853c
to
21ba4d9
Compare
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
c303544
to
ed8e2f9
Compare
Now, Current_directory (initial directory) is also supported. It should be an external storage directory, users can use func _show_native_file_picker() -> void:
var filters = PackedStringArray(["image/*","text/plain","application/pdf"])
var current_directory = OS.get_system_dir(OS.SYSTEM_DIR_DOCUMENTS)
DisplayServer.file_dialog_show("title", current_directory, "filename", false, DisplayServer.FILE_DIALOG_MODE_OPEN_FILE, filters, _picker_callback)
func _picker_callback(status: bool, selected_paths: PackedStringArray, selected_filter_index: int):
$Label.text += str("Status: ",status,"\n")
$Label.text += str("Selected Paths: ",selected_paths,"\n\n")
|
ed8e2f9
to
6037838
Compare
This is now ready for review, and all features are functioning as expected in my tests. Regarding the two unchecked tasks:
Please let me know if any additional adjustments are needed! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since implementation is limited (which is expected for Android), limitations (no options, no usr://
and res://
access) should be mentioned in the class reference documentation for FileDialog
and DisplayServer
:
DisplayServer
:
godot/doc/classes/DisplayServer.xml
Line 130 in 44fa552
<method name="file_dialog_show"> |
godot/doc/classes/DisplayServer.xml
Line 150 in 44fa552
<method name="file_dialog_with_options_show"> |
FileDialog
:
godot/doc/classes/FileDialog.xml
Line 166 in 44fa552
<member name="use_native_dialog" type="bool" setter="set_use_native_dialog" getter="get_use_native_dialog" default="false"> |
godot/doc/classes/FileDialog.xml
Line 22 in 44fa552
<method name="add_option"> |
Also, it might be worth adding new DisplayServer
feature flags for options
and res/usr access
, and check these flags in the FileDialog
to automatically switch to embedded dialog when incompatible options are used.
This comment was marked as outdated.
This comment was marked as outdated.
@bruvzg how about only one new feature tag FEATURE_NATIVE_DIALOG_FILE_EXTRA ? |
One flag should be OK (iOS will have the same limitations). |
8cd0a88
to
fd58b7e
Compare
platform/android/java/lib/src/org/godotengine/godot/io/file/MediaStoreData.kt
Outdated
Show resolved
Hide resolved
platform/android/java/lib/src/org/godotengine/godot/io/file/MediaStoreData.kt
Outdated
Show resolved
Hide resolved
platform/android/java/lib/src/org/godotengine/godot/io/file/MediaStoreData.kt
Outdated
Show resolved
Hide resolved
40a8199
to
cc0ad6a
Compare
platform/android/java/lib/src/org/godotengine/godot/FilePicker.kt
Outdated
Show resolved
Hide resolved
platform/android/java/lib/src/org/godotengine/godot/FilePicker.kt
Outdated
Show resolved
Hide resolved
platform/android/java/lib/src/org/godotengine/godot/FilePicker.kt
Outdated
Show resolved
Hide resolved
cc0ad6a
to
872f6c7
Compare
@syntaxerror247 can I have the APK to test? |
@UnderGamer05 I have uploaded the apk, check in PR description. |
Hi @m4gr3d , just checking in to see if the updates I made in the PR align with what you had in mind. Let me know if there's anything else you'd like me to tweak. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
Added some minor comments to address.
platform/android/java/lib/src/org/godotengine/godot/io/file/MediaStoreData.kt
Outdated
Show resolved
Hide resolved
platform/android/java/lib/src/org/godotengine/godot/io/file/MediaStoreData.kt
Outdated
Show resolved
Hide resolved
platform/android/java/lib/src/org/godotengine/godot/io/file/MediaStoreData.kt
Outdated
Show resolved
Hide resolved
platform/android/java/lib/src/org/godotengine/godot/io/FilePicker.kt
Outdated
Show resolved
Hide resolved
872f6c7
to
6c7ef40
Compare
platform/android/java/lib/src/org/godotengine/godot/GodotLib.java
Outdated
Show resolved
Hide resolved
6c7ef40
to
025a538
Compare
…er/res` and `options`
7dcfa62
to
64a4c2b
Compare
64a4c2b
to
b2130ef
Compare
Rebased and resolved conflicts. |
Thanks! |
@syntaxerror247 Just tested the test apk provided here and when opening the resources it doesn't open the native file picker is that intentional? I also tested this on v4.4 Dev 5 and when I try to use the native file dialog (not through code) and setting the access as ACCESS_FILESYSTEM the app immediately closes when I press the button. I believe I have checked the needed read user directory permissions (It asked to enable the same permission as the test apk you provided). Did you do this through code? |
@ThatSimpleDev Yes, that intentional. Android doesn't allow access to user:// and res:// directory, that's why it fallbacks to custom Filedialog.
Yes, This is a regression due an update to FileDialog. This issue wasn't present in dev4. This will be solved after these two PRs #99350 and #99385 are merged. For now, you can use it via code. |
First commit, creates a new DisplayServer Flag FEATURE_NATIVE_DIALOG_FILE_EXTRA, for access to USERDATA and RESOURCES directory and OPTIONS feature. Native File Dialog will fallback to custom one if not supported.
Second commit, implements native file picker support for android
This Partially addresses
Allow use of native system file picker dialog on iOS and web godot-proposals#1123
Add support for Android native file dialogs godot-proposals#10983
Test App (arm64): Test.zip
Demo Video
VID_20241021_215329.mp4
Task List
Options supportNot possible with system file picker.show hiddenIt can be set manually with system file picker.selected filter index callbackNot possible with multi select, that's why omited this feature entirely.access mode RESOURCES and USERDATA supportNot possible with native picker, will fallback to custom one.