From 8b8d5d89970549f5b321b69960888041cabe8fcf Mon Sep 17 00:00:00 2001 From: Steve Hannah Date: Sun, 25 Feb 2024 14:34:12 -0800 Subject: [PATCH] fix: Android browser component now works with multi-file selection. Ticket: https://github.com/codenameone/CodenameOne/issues/3787 --- .../impl/android/AndroidImplementation.java | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/Ports/Android/src/com/codename1/impl/android/AndroidImplementation.java b/Ports/Android/src/com/codename1/impl/android/AndroidImplementation.java index ff2792fa3e..fea1347972 100644 --- a/Ports/Android/src/com/codename1/impl/android/AndroidImplementation.java +++ b/Ports/Android/src/com/codename1/impl/android/AndroidImplementation.java @@ -7982,10 +7982,29 @@ public void onActivityResult(int requestCode, int resultCode, Intent intent) { if (requestCode == REQUEST_SELECT_FILE || requestCode == FILECHOOSER_RESULTCODE) { if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (requestCode == REQUEST_SELECT_FILE) { - if (uploadMessage == null) { - return; + if (uploadMessage == null) return; + Uri[] results = null; + + // Check that the response is a good one + if (resultCode == Activity.RESULT_OK) { + if (intent != null) { + // If there is not data, then we may have taken a photo + String dataString = intent.getDataString(); + ClipData clipData = intent.getClipData(); + + if (clipData != null) { + results = new Uri[clipData.getItemCount()]; + for (int i = 0; i < clipData.getItemCount(); i++) { + ClipData.Item item = clipData.getItemAt(i); + results[i] = item.getUri(); + } + } else if (dataString != null) { + results = new Uri[]{Uri.parse(dataString)}; + } + } } - uploadMessage.onReceiveValue(WebChromeClient.FileChooserParams.parseResult(resultCode, intent)); + + uploadMessage.onReceiveValue(results); uploadMessage = null; } }