Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android input type=file with multiple mime types in "accept" only uses the first mime type #874

Closed
3 tasks done
Michael-Shemesh opened this issue Nov 26, 2019 · 3 comments

Comments

@Michael-Shemesh
Copy link

Michael-Shemesh commented Nov 26, 2019

Problem

When opening the native file chooser of android from an html with multiple accept mime types, only the first mime type is being used to filter the allowed files.
For example, <input type="file" accept="image/png, image/gif" /> will only allow you to choose a file of type png and not gif.

In addition, if the "accept" attribute is not specified at all, no files can be selected at all.

What is expected to happen?

When there are multiple mime types in the accept attribute, all of mime types should be allowed to be chosen from the native file chooser.

What does actually happen?

Only the first mime type is accepted and all other file types are disabled and can't be chosen.

Information

To reproduce, just create a new cordova-android project, in the index.html file, add the following:
<input type="file" accept="image/png, image/gif" />
Run the project on a device of emulator and try to select a gif file.

Command or Code

The issue is in the SystemWebChromeClient class, the accept types need to be added as extra arguments to the intent that is bring created by the fileChooserParams.
i.e., the following should fix the issue:
intent.putExtra(Intent.EXTRA_MIME_TYPES, fileChooserParams.getAcceptTypes());

The function with the fixed code should look like this:

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public boolean onShowFileChooser(WebView webView, final ValueCallback<Uri[]> filePathsCallback, final WebChromeClient.FileChooserParams fileChooserParams) {
    ....
    Intent intent = fileChooserParams.createIntent();
    if(fileChooserParams.getAcceptTypes() != null) {
        intent.putExtra(Intent.EXTRA_MIME_TYPES, fileChooserParams.getAcceptTypes());
    }
    ....
}

Environment, Platform, Device

Cordova-android: 8.1.0
Cordova-CLI: 9.0.0
Device: Samsung Galaxy S9

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above
@WuglyakBolgoink
Copy link

related to #707

@ksch10bob
Copy link

solved by PR #971

@jcesarmobile
Copy link
Member

closing since #971 was merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants