diff --git a/framework/src/org/apache/cordova/engine/SystemWebChromeClient.java b/framework/src/org/apache/cordova/engine/SystemWebChromeClient.java index 72846f0fc1..a2b2c1fc9f 100755 --- a/framework/src/org/apache/cordova/engine/SystemWebChromeClient.java +++ b/framework/src/org/apache/cordova/engine/SystemWebChromeClient.java @@ -250,13 +250,34 @@ public void onActivityResult(int requestCode, int resultCode, Intent intent) { @TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override public boolean onShowFileChooser(WebView webView, final ValueCallback filePathsCallback, final WebChromeClient.FileChooserParams fileChooserParams) { + // Check if multiple-select is specified + Boolean selectMultiple = false; + if (fileChooserParams.getMode() == WebChromeClient.FileChooserParams.MODE_OPEN_MULTIPLE) { + selectMultiple = true; + } Intent intent = fileChooserParams.createIntent(); + intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, selectMultiple); try { parentEngine.cordova.startActivityForResult(new CordovaPlugin() { @Override public void onActivityResult(int requestCode, int resultCode, Intent intent) { - Uri[] result = WebChromeClient.FileChooserParams.parseResult(resultCode, intent); - LOG.d(LOG_TAG, "Receive file chooser URL: " + result); + Uri[] result = null; + if (resultCode == Activity.RESULT_OK && intent != null) { + if (intent.getClipData() != null) { + // handle multiple-selected files + final int numSelectedFiles = intent.getClipData().getItemCount(); + result = new Uri[numSelectedFiles]; + for (int i = 0; i < numSelectedFiles; i++) { + result[i] = intent.getClipData().getItemAt(i).getUri(); + LOG.d(LOG_TAG, "Receive file chooser URL: " + result[i]); + } + } + else if (intent.getData() != null) { + // handle single-selected file + result = WebChromeClient.FileChooserParams.parseResult(resultCode, intent); + LOG.d(LOG_TAG, "Receive file chooser URL: " + result); + } + } filePathsCallback.onReceiveValue(result); } }, intent, FILECHOOSER_RESULTCODE);