Skip to content

Commit

Permalink
Merge pull request godotengine#100607 from syntaxerror247/fix-filepicker
Browse files Browse the repository at this point in the history
Fix Android native file picker
  • Loading branch information
Repiteo committed Dec 20, 2024
2 parents 151e7fc + 9deee00 commit 89001f9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,10 @@ internal class FilePicker {
}
// ACTION_OPEN_DOCUMENT_TREE does not support intent type
if (fileMode != FILE_MODE_OPEN_DIR) {
intent.type = "*/*"
if (filters.isNotEmpty()) {
val resolvedFilters = filters.map { resolveMimeType(it) }.distinct()
if (resolvedFilters.size == 1) {
intent.type = resolvedFilters[0]
} else {
intent.putExtra(Intent.EXTRA_MIME_TYPES, resolvedFilters.toTypedArray())
}
val resolvedFilters = filters.map { resolveMimeType(it) }.distinct()
intent.type = resolvedFilters.firstOrNull { it != "application/octet-stream" } ?: "*/*"
if (resolvedFilters.size > 1) {
intent.putExtra(Intent.EXTRA_MIME_TYPES, resolvedFilters.toTypedArray())
}
intent.addCategory(Intent.CATEGORY_OPENABLE)
}
Expand Down
2 changes: 1 addition & 1 deletion platform/android/java_godot_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ Error GodotJavaWrapper::show_file_picker(const String &p_current_directory, cons
jint j_mode = p_mode;
jobjectArray j_filters = env->NewObjectArray(p_filters.size(), env->FindClass("java/lang/String"), nullptr);
for (int i = 0; i < p_filters.size(); ++i) {
jstring j_filter = env->NewStringUTF(p_filters[i].utf8().get_data());
jstring j_filter = env->NewStringUTF(p_filters[i].get_slice(";", 0).utf8().get_data());
env->SetObjectArrayElement(j_filters, i, j_filter);
env->DeleteLocalRef(j_filter);
}
Expand Down

0 comments on commit 89001f9

Please sign in to comment.