Missing Intent type and category prevent file upload - [solution included]
See original GitHub issueBug Report
Files upload not working on Android when the Cordova App uses ng-file-upload.
( works on iOS 👇👇 )
Problem
Using ng-file-upload it is not possible to upload images or document on Android when the App is built using Cordova.
The 2 lines fix suggested below will resolve the Issue opened here on the ng-file-upload repository and the related Stackoverflow.
This is the line after which the following 2 lines of code need to be added: https://github.com/apache/cordova-android/blob/2163c8ae0536bfde9029cfc981b945f4af93e09f/framework/src/org/apache/cordova/engine/SystemWebChromeClient.java#L253
Bug fix - 2 lines of code:
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public boolean onShowFileChooser(WebView webView, final ValueCallback<Uri[]> filePathsCallback, final WebChromeClient.FileChooserParams fileChooserParams) {
Intent intent = fileChooserParams.createIntent();
// FIX HERE (same as the above handler) vvvvvvvvvvvvvv @@
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
// FIX HERE ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@
What is expected to happen?
The user should be prompted to choose which app to use to pick a file to upload
What does actually happen?
On click no file picker is shown
Information
These logs get generated when the upload button that should open the file picker is clicked:
“No activity found to handle file chooser intent.: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.GET_CONTENT cat= [android.intent.category.OPENABLE] typ=.jpg,.png,.tiff,.jpeg,.tif,.pdf }”
Command or Code
Unfortunately I cannot share the code.
Environment, Platform, Device
Android app built with Cordova.
Same result using the default WebView and the WebView provided by cordova-plugin-ionic-webview.
Version information
Same result on cordova-android 7 and 8.
Checklist
- I searched for existing GitHub issues
- I updated all Cordova tooling to most recent version
- I included all the necessary information above
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:13 (5 by maintainers)
@breautek i can only speak for android Versions from 5.xx
case 1 : no or an empty accept attribute is specified. Works like intended, you get the fully featured file picker
case 2 : your specify an accept attribute on the input tag that contains at least 2 entries try
<input type="file" accept="application/pdf, image/jpeg" />
in your minimal cordova repoexpected
you can choose jpegs and pdfs
actually
you can only choose pdfs
I didn’t try that specifically but for android omitting the
accept
attribute had the effect of allowing any file.