Skip to content

Commit a28697f

Browse files
Android: Fix save issue when using native file dialog
Fixes the issue where saving a file without `MANAGE_EXTERNAL_STORAGE` permission using the `native file dialog` to get the file path causes the `ERR_FILE_NOT_FOUND` error.
1 parent 5dd7696 commit a28697f

File tree

1 file changed

+11
-2
lines changed
  • platform/android/java/lib/src/org/godotengine/godot/io

1 file changed

+11
-2
lines changed

platform/android/java/lib/src/org/godotengine/godot/io/FilePicker.kt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import org.godotengine.godot.io.file.MediaStoreData
5151
internal class FilePicker {
5252
companion object {
5353
private const val FILE_PICKER_REQUEST = 1000
54+
private const val FILE_SAVE_REQUEST = 1001
5455
private val TAG = FilePicker::class.java.simpleName
5556

5657
// Constants for fileMode values
@@ -70,7 +71,7 @@ internal class FilePicker {
7071
*/
7172
@RequiresApi(Build.VERSION_CODES.Q)
7273
fun handleActivityResult(context: Context, requestCode: Int, resultCode: Int, data: Intent?) {
73-
if (requestCode == FILE_PICKER_REQUEST) {
74+
if (requestCode == FILE_PICKER_REQUEST || requestCode == FILE_SAVE_REQUEST) {
7475
if (resultCode == Activity.RESULT_CANCELED) {
7576
Log.d(TAG, "File picker canceled")
7677
GodotLib.filePickerCallback(false, emptyArray())
@@ -101,6 +102,10 @@ internal class FilePicker {
101102
} else {
102103
Log.d(TAG, "null filepath URI: $it")
103104
}
105+
106+
if (requestCode == FILE_SAVE_REQUEST) {
107+
DocumentsContract.deleteDocument(context.contentResolver, it)
108+
}
104109
}
105110
}
106111

@@ -152,7 +157,11 @@ internal class FilePicker {
152157
intent.addCategory(Intent.CATEGORY_OPENABLE)
153158
}
154159
intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true)
155-
activity?.startActivityForResult(intent, FILE_PICKER_REQUEST)
160+
if (fileMode == FILE_MODE_SAVE_FILE) {
161+
activity?.startActivityForResult(intent, FILE_SAVE_REQUEST)
162+
} else {
163+
activity?.startActivityForResult(intent, FILE_PICKER_REQUEST)
164+
}
156165
}
157166

158167
/**

0 commit comments

Comments
 (0)