ng-file-upload
ng-file-upload copied to clipboard
ng-file-upload not working for Android in Ionic / Cordova projects
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:
- https://github.com/apache/cordova-plugin-file-transfer#deprecated => NOW DEPRECATED
- Crosswalk => NOW DEPRECATED
How can I solve this please? The HTTP request is not sent at all.
Additional info:
- 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
- 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>
-
I am whitelisting everything in my config.xml for cordova: access, allow-navigation, allow-intent, CSP. Still no luck.
-
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);
( raised also on Stackoverflow: https://stackoverflow.com/questions/55261705/file-upload-not-working-for-android-in-cordova-project )
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.
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?
@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.
@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.