@@ -131,6 +131,14 @@ object FileUtils {
131131 }
132132 }
133133
134+ /* *
135+ * Creates and launches an intent for the given file type.
136+ *
137+ * This method is responsible for creating the appropriate intent based on the [type] of file
138+ * that is requested to be picked.
139+ *
140+ * This may be either a directory, a regular file, or a gallery pick.
141+ */
134142 fun FilePickerDelegate.startFileExplorer () {
135143 val intent: Intent
136144
@@ -143,6 +151,7 @@ object FileUtils {
143151 intent = Intent (Intent .ACTION_OPEN_DOCUMENT_TREE )
144152 } else {
145153 if (type == " image/*" ) {
154+ // Use ACTION_PICK for images to allow using the Gallery app, which provides a better UX for image selection.
146155 intent = Intent (Intent .ACTION_PICK )
147156 val uri = (Environment .getExternalStorageDirectory().path + File .separator).toUri()
148157 intent.setDataAndType(uri, type)
@@ -159,6 +168,11 @@ object FileUtils {
159168 intent.putExtra(Intent .EXTRA_MIME_TYPES , allowedExtensions)
160169 }
161170 } else {
171+ // Use ACTION_OPEN_DOCUMENT to allow selecting files from any document provider (SAF).
172+ // We prefer ACTION_OPEN_DOCUMENT over ACTION_GET_CONTENT because it offers persistent
173+ // access to the files via URI permissions, which is crucial for some use cases
174+ // (e.g. caching, repeated access). ACTION_GET_CONTENT is more suitable for
175+ // "importing" content and might not provide a persistent URI.
162176 intent = Intent (Intent .ACTION_OPEN_DOCUMENT ).apply {
163177 addCategory(Intent .CATEGORY_OPENABLE )
164178 type = this @startFileExplorer.type
@@ -186,6 +200,16 @@ object FileUtils {
186200 }
187201 }
188202
203+ /* *
204+ * Called by the plugin to start a new file explorer activity.
205+ *
206+ * @param type The file types that will be selectable.
207+ * @param isMultipleSelection Whether multiple files can be selected.
208+ * @param withData Whether the file data should be loaded into memory.
209+ * @param allowedExtensions The allowed file extensions for custom file types.
210+ * @param compressionQuality The compression quality for images.
211+ * @param result The result channel to send the file picking result to.
212+ */
189213 fun FilePickerDelegate?.startFileExplorer (
190214 type : String? ,
191215 isMultipleSelection : Boolean? ,
0 commit comments