Skip to content

Commit

Permalink
feat: added multiple selection for filepicker (#651)
Browse files Browse the repository at this point in the history
* GH-621 (Cordova-Android)
  • Loading branch information
MatusFiala authored and erisu committed Sep 8, 2019
1 parent f2b84d8 commit 42c0cba
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions framework/src/org/apache/cordova/engine/SystemWebChromeClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Uri[]> 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);
Expand Down

1 comment on commit 42c0cba

@rubenstolk
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yourock

Please sign in to comment.