0

In my Cordova project I rely on a third party dependency that uses ng-file-upload in order to upload files.

It works on iOS but not on Android as reported in this issue on their Github.

The old issue had been closed because the following solutions were available:

How can I solve this? The HTTP request is not sent at all.


Additional info:

  1. Logs found in LogCat:

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 }

Explanation of the log: The error is telling you that the device has no applications installed that are able to handle that particular implicit intent. -> that is not the case though

  1. It does not seem to be a permissions issue: The (Cordova) Android App works when for the upload button I use <input type="file" /> in place of the ng-file-upload directive.

( we already provide all the required permissions: )

        <custom-config-file parent="/*" target="AndroidManifest.xml">
            <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
            <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
            <uses-permission android:name="android.permission.MANAGE_DOCUMENTS" />
            <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
        </custom-config-file>
  1. I am whitelisting everything in my config.xml for cordova: access, allow-navigation, allow-intent, CSP. Still no luck.

  2. We don't have control over the Android code (unless we write a custom plugin). Would this native code solve the issue?

MyWebviewSettings.setJavaScriptCanOpenWindowsAutomatically(true);
MyWebviewSettings.setJavaScriptEnabled(true);

myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.getSettings().setAllowFileAccessFromFileURLs(true);
myWebView.getSettings().setAllowUniversalAccessFromFileURLs(true);
Gabe
  • 5,997
  • 5
  • 46
  • 92
  • I will give a **50 rep bounty** to whoever helps us solve this. Thanks :) – Gabe Mar 20 '19 at 15:53
  • Update: I have been told that someone managed to make ng-file-upload work using inappbrowser. Giving it a try.. – Gabe Mar 20 '19 at 16:42

1 Answers1

1

We solved this bug adding the 2 lines of code below that were missing in the Lollipop (and greater versions) handler.

@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 vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv @@
    intent.addCategory(Intent.CATEGORY_OPENABLE); 
    intent.setType("*/*");
    // FIX HERE ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@

This handler in your cordova project is located under: src/org/apache/cordova/engine/SystemWebChromeClient.java.

Hopefully the contributors of cordova-android will fix this reported issue themselves so that we can remove our patch.

Gabe
  • 5,997
  • 5
  • 46
  • 92
  • Better solution: https://stackoverflow.com/questions/55447711/convert-mime-types-in-filechooserparams-to-the-right-format-for-intent-settype – Gabe Apr 01 '19 at 15:56