Android: Implement Storage Access Framework (SAF) support#112215
Android: Implement Storage Access Framework (SAF) support#112215akien-mga merged 1 commit intogodotengine:masterfrom
Conversation
platform/android/java/lib/src/main/java/org/godotengine/godot/io/file/SAFData.kt
Outdated
Show resolved
Hide resolved
platform/android/java/lib/src/main/java/org/godotengine/godot/io/StorageScope.kt
Outdated
Show resolved
Hide resolved
e64d040 to
67f9224
Compare
platform/android/java/lib/src/main/java/org/godotengine/godot/io/file/DataAccess.kt
Outdated
Show resolved
Hide resolved
f4c17d8 to
ad1e925
Compare
|
Added support for DocumentTree to allow full access to a directory and do file operations using file paths in this selected directory. For example, when a directory is selected using FILE_DIALOG_MODE_OPEN_DIR, you receive a This is now almost ready, only the documentation is left. So, please start reviewing it in the meantime. The sample code is included in the PR description. |
platform/android/java/lib/src/main/java/org/godotengine/godot/io/file/DataAccess.kt
Outdated
Show resolved
Hide resolved
platform/android/java/lib/src/main/java/org/godotengine/godot/io/file/SAFData.kt
Show resolved
Hide resolved
platform/android/java/lib/src/main/java/org/godotengine/godot/io/file/SAFData.kt
Show resolved
Hide resolved
platform/android/java/lib/src/main/java/org/godotengine/godot/io/file/SAFData.kt
Outdated
Show resolved
Hide resolved
platform/android/java/lib/src/main/java/org/godotengine/godot/io/file/SAFData.kt
Outdated
Show resolved
Hide resolved
ca36f33 to
b1a5d72
Compare
platform/android/java/lib/src/main/java/org/godotengine/godot/io/file/SAFData.kt
Outdated
Show resolved
Hide resolved
platform/android/java/lib/src/main/java/org/godotengine/godot/io/file/SAFData.kt
Outdated
Show resolved
Hide resolved
platform/android/java/lib/src/main/java/org/godotengine/godot/io/file/SAFData.kt
Outdated
Show resolved
Hide resolved
platform/android/java/lib/src/main/java/org/godotengine/godot/io/file/SAFData.kt
Outdated
Show resolved
Hide resolved
platform/android/java/lib/src/main/java/org/godotengine/godot/io/FilePicker.kt
Show resolved
Hide resolved
platform/android/java/lib/src/main/java/org/godotengine/godot/io/FilePicker.kt
Show resolved
Hide resolved
m4gr3d
left a comment
There was a problem hiding this comment.
The code looks good!
Do you think you can turn the sample gdscript code into instrumented tests the way we did for javaclasswrapper?
|
@syntaxerror247 Once the feature is stable, we should look into updating the Android editor to make use of it (potentially for 4.7). |
Yes, I can try. |
6442580 to
60d20ab
Compare
From a google search, it seems to be possible to use espresso to interact with the SAF file picker UI. |
Hmm, I thought Espresso was only for app UI testing, it can’t interact with system UI. But I might be wrong since I haven't looked into it much. |
|
Thanks! |
|
Hi everyone, I'm not sure if you could help me with this. I don't know how to implement the SAF system to save the internal MP3 files of the app I created in Godot to my phone. The MP3 files are located in the res:// folder, and I'd like to save them to a folder on my phone that's easily accessible outside of the app. |
func _pick_file() -> void:
var filters = PackedStringArray(["*.mp3"])
var current_directory = OS.get_system_dir(OS.SYSTEM_DIR_MUSIC)
var filename = "music.mp3"
DisplayServer.file_dialog_show("title", current_directory, filename, false, DisplayServer.FILE_DIALOG_MODE_SAVE_FILE, filters, _picker_callback)
func _picker_callback(status: bool, selected_uris: PackedStringArray, _selected_filter_index: int):
var source_file = load("res://music.mp3")
var destination_path = selected_uris[0]
var f = FileAccess.open(destination_path, FileAccess.WRITE)
f.store_buffer(source_file.data)
f.close()You can use this sample code to copy the file But please note that questions like this are better suited for the Godot community servers or the official forum: https://godotengine.org/community/ |
|
@syntaxerror247 |
|
Hello @syntaxerror247 The card for this PR is inside the Platforms > Android section (https://gtibo.github.io/godot-4.6-release-page/) |
Closes godotengine/godot-proposals#12669
Resolves #112136
This PR implements full SAF support:
FileAccessto perform standard read/write operations.FILE_DIALOG_MODE_OPEN_DIR.tree URI, giving you full access to that directory. You can open/create files inside it directly with paths, without reopening the file picker.FileAccessas usual, but the path should follow the formattreeUri#relative/path/to/file.Sample code for testing
Edit: To be able to reuse the URI across app restarts, you need to request persistable permission. See #113367