@@ -56,20 +56,18 @@ class DialogPlugin(private val activity: Activity): Plugin(activity) {
5656 try {
5757 val args = invoke.parseArgs(FilePickerOptions ::class .java)
5858 val parsedTypes = parseFiltersOption(args.filters)
59-
60- val intent = if (parsedTypes.isNotEmpty()) {
61- val intent = Intent (Intent .ACTION_PICK )
62- setIntentMimeTypes(intent, parsedTypes)
63- intent
64- } else {
65- val intent = Intent (Intent .ACTION_GET_CONTENT )
66- intent.addCategory(Intent .CATEGORY_OPENABLE )
67- intent.type = " */*"
68- intent
59+
60+ // TODO: ACTION_OPEN_DOCUMENT ??
61+ val intent = Intent (Intent .ACTION_GET_CONTENT )
62+ intent.addCategory(Intent .CATEGORY_OPENABLE )
63+ intent.type = " */*"
64+
65+ if (parsedTypes.isNotEmpty()) {
66+ intent.putExtra(Intent .EXTRA_MIME_TYPES , parsedTypes)
6967 }
7068
7169 intent.putExtra(Intent .EXTRA_ALLOW_MULTIPLE , args.multiple ? : false )
72-
70+
7371 startActivityForResult(invoke, intent, " filePickerResult" )
7472 } catch (ex: Exception ) {
7573 val message = ex.message ? : " Failed to pick file"
@@ -115,7 +113,7 @@ class DialogPlugin(private val activity: Activity): Plugin(activity) {
115113 callResult.put(" files" , JSArray .from(uris.toTypedArray()))
116114 return callResult
117115 }
118-
116+
119117 private fun parseFiltersOption (filters : Array <Filter >): Array <String > {
120118 val mimeTypes = mutableListOf<String >()
121119 for (filter in filters) {
@@ -132,38 +130,10 @@ class DialogPlugin(private val activity: Activity): Plugin(activity) {
132130 return mimeTypes.toTypedArray()
133131 }
134132
135- private fun setIntentMimeTypes (intent : Intent , mimeTypes : Array <String >) {
136- if (mimeTypes.isNotEmpty()) {
137- var uniqueMimeKind = true
138- var mimeKind: String? = null
139- for (mime in mimeTypes) {
140- val kind = mime.split(" /" )[0 ]
141- if (mimeKind == null ) {
142- mimeKind = kind
143- } else if (mimeKind != kind) {
144- uniqueMimeKind = false
145- }
146- }
147-
148- if (uniqueMimeKind) {
149- if (mimeTypes.size > 1 ) {
150- intent.putExtra(Intent .EXTRA_MIME_TYPES , mimeTypes)
151- intent.type = Intent .normalizeMimeType(" $mimeKind /*" )
152- } else {
153- intent.type = mimeTypes[0 ]
154- }
155- } else {
156- intent.type = " */*"
157- }
158- } else {
159- intent.type = " */*"
160- }
161- }
162-
163133 @Command
164134 fun showMessageDialog (invoke : Invoke ) {
165135 val args = invoke.parseArgs(MessageOptions ::class .java)
166-
136+
167137 if (activity.isFinishing) {
168138 invoke.reject(" App is finishing" )
169139 return
@@ -179,7 +149,7 @@ class DialogPlugin(private val activity: Activity): Plugin(activity) {
179149 Handler (Looper .getMainLooper())
180150 .post {
181151 val builder = AlertDialog .Builder (activity)
182-
152+
183153 if (args.title != null ) {
184154 builder.setTitle(args.title)
185155 }
@@ -213,10 +183,14 @@ class DialogPlugin(private val activity: Activity): Plugin(activity) {
213183 val parsedTypes = parseFiltersOption(args.filters)
214184
215185 val intent = Intent (Intent .ACTION_CREATE_DOCUMENT )
216- setIntentMimeTypes(intent, parsedTypes)
217-
218186 intent.addCategory(Intent .CATEGORY_OPENABLE )
219187 intent.putExtra(Intent .EXTRA_TITLE , args.fileName ? : " " )
188+ intent.type = " */*"
189+
190+ if (parsedTypes.isNotEmpty()) {
191+ intent.putExtra(Intent .EXTRA_MIME_TYPES , parsedTypes)
192+ }
193+
220194 startActivityForResult(invoke, intent, " saveFileDialogResult" )
221195 } catch (ex: Exception ) {
222196 val message = ex.message ? : " Failed to pick save file"
0 commit comments