danialfarid / ng-file-upload

Lightweight Angular directive to upload files with optional FileAPI shim for cross browser support
MIT License
7.87k stars 1.59k forks source link

ng-file-upload not working for Android in Ionic / Cordova projects #2111

Open gabriele-sacchi opened 5 years ago

gabriele-sacchi commented 5 years ago

How can I make this directive work in a Cordova project?

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

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

How can I solve this please? 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

  2. 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 your 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);

gabriele-sacchi commented 5 years ago

( raised also on Stackoverflow: https://stackoverflow.com/questions/55261705/file-upload-not-working-for-android-in-cordova-project )

gabriele-sacchi commented 5 years ago

Issue solved with this PR: https://github.com/apache/cordova-android/pull/707

I'm currently using this forked version of cordova-android until my Pull Request gets approved.

WuglyakBolgoink commented 5 years ago

Hallo @gabriele-sacchi

I try to do a local fix, but it doesn't work... how you test this fix? and with which cordova/cordova-android versions is it compatible/possible?

gine commented 4 years ago

@gabriele-sacchi what do you have writen on your ng-file upload directive? You branch on my huawei 8.1 with ngf-camera="'other'" or ngf-capture="'camera'" and ngf-accept="'image/*'" doesn't work.

gine commented 4 years ago

@WuglyakBolgoink did you find any solution to test it?

I did only:

ionic cordova platform add https://github.com/gabriele-sacchi/cordova-android

then in node_modules/cordova-android i have the patched version but to me doesn't work.