Skip to content

Commit ed5206e

Browse files
committed
Refactor: Simplify MIME type handling in file explorer intent
This commit refactors the logic for setting MIME types in the `ACTION_OPEN_DOCUMENT` intent. Previously, `Intent.ACTION_PICK` was used for specific image types. This has been removed in favor of consistently using `ACTION_OPEN_DOCUMENT`. The handling of `EXTRA_MIME_TYPES` has been simplified: - If `allowedExtensions` is provided, it's used as the value for `EXTRA_MIME_TYPES`. - If `allowedExtensions` is null or empty, the primary `type` is used instead.
1 parent 1a71293 commit ed5206e

File tree

1 file changed

+6
-5
lines changed
  • android/src/main/kotlin/com/mr/flutter/plugin/filepicker

1 file changed

+6
-5
lines changed

android/src/main/kotlin/com/mr/flutter/plugin/filepicker/FileUtils.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ object FileUtils {
142142
if (type == "dir") {
143143
intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE)
144144
} else {
145-
if (type == "image/*") {
145+
if (type != "*/*") {
146146
intent = Intent(Intent.ACTION_PICK)
147147
val uri = (Environment.getExternalStorageDirectory().path + File.separator).toUri()
148148
intent.setDataAndType(uri, type)
@@ -162,12 +162,13 @@ object FileUtils {
162162
intent = Intent(Intent.ACTION_OPEN_DOCUMENT).apply {
163163
addCategory(Intent.CATEGORY_OPENABLE)
164164
type = this@startFileExplorer.type
165+
if (!allowedExtensions.isNullOrEmpty()) {
166+
putExtra(Intent.EXTRA_MIME_TYPES, allowedExtensions!!.toTypedArray())
167+
}else{
168+
putExtra(Intent.EXTRA_MIME_TYPES, this@startFileExplorer.type)
169+
}
165170
putExtra(Intent.EXTRA_ALLOW_MULTIPLE, isMultipleSelection)
166171
putExtra("multi-pick", isMultipleSelection)
167-
168-
allowedExtensions?.let {
169-
putExtra(Intent.EXTRA_MIME_TYPES, it.toTypedArray())
170-
}
171172
}
172173

173174
}

0 commit comments

Comments
 (0)