You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by GitBox <gi...@apache.org> on 2019/11/26 17:00:13 UTC

[GitHub] [cordova-android] Michael-Shemesh opened a new issue #874: Android input type=file with multiple mime types in "accept" only uses the first mime type

Michael-Shemesh opened a new issue #874: Android input type=file with multiple mime types in "accept" only uses the first mime type
URL: https://github.com/apache/cordova-android/issues/874
 
 
   ## Problem
   When opening the native file chooser of android from an html <input type=file> 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.
   
   
   ### 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
   <!-- Please check the boxes by putting an x in the [ ] like so: [x] -->
   
   - [x] I searched for existing GitHub issues
   - [x] I updated all Cordova tooling to most recent version
   - [x] I included all the necessary information above
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org