danialfarid / ng-file-upload

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

ngf-capture="camera" won't open up camera application (opens photo gallery instead) in Cordova app #1984

Open gkimpson opened 7 years ago

gkimpson commented 7 years ago

I am trying to use the ngf-camera attribute to enable access to the camera, I have added the relevent info to the Android Manifest xml file for permissions.

In the view I have the following code and for some reason it will always open up the Phone Gallery rather than open the camera application, can anyone suggest what I am doing wrong?

<input type="file" ngf-select="onCameraSelect(file)" ngf-fix-orientation="true" ngf-capture="'camera'" ng-model="file" accept="image/*">

I want this to enable me to take a photo directly from the camera - is there any obvious reason why it won't open the camera application? I am using the latest version of ng-file-upload, my mobile application is running Cordova/AngularJS

Cordova 6.5.0 NPM 5.3.0 Node 6.10.3 Running code on multiple Android devices 6.0 & 7.1.1 ng-file-upload 12.2.13 AngularJS 1.3.0

Arxi commented 7 years ago

@gkimpson have you found a solution to this problem? I have the same. I suspect it might have something to do with permissions.

gkimpson commented 7 years ago

@Arxi I believe we got around this using ngf-camera="other" instead also make sure the permissions are set - add the cordova camera plugin as this will add the permissions. Hope that helps 👍

Arxi commented 7 years ago

@gkimpson thanks for your reply! I tried ngf-camera="other", but nothing changes. I also have the cordova camera plugin installed, but it doesn't seem to add the necessary permissions to AndroidManifest or ask about the right permissions for camera in Android 7, so I added the permissions manually and also asked for them. Still, the problem persists.

Would you be so kind as to share a bit of your HTML or JS to see how you hande this? Or maybe your Content Security Policy from index.html, or allow-intent tags from config.xml? I don't know if these might affect this behaviour. Thank you!

The strange part is, that when I try the demo page in Chrome 60.0.3112.107 (in Android), it shows the app chooser correctly (Camera, Camcorder, File). When trying the same code in the app (Android 7.1.1, WebView 60.0.3112.107 - the same as Chrome, Cordova 7.0.1, cordova android 6.2.3), it goes straight to file chooser, no camera/camcorder option available.

gkimpson commented 7 years ago

You are very welcome @Arxi I just remember how I got around this was to install CrossWalk - due to the issue with the webview in Android. This worked however it seemed to cause some issues with the app crashing on old devices (seemed fine on my newer OnePlus 3 device) https://github.com/crosswalk-project/cordova-plugin-crosswalk-webview

You install this like any normal cordova plugin e.g cordova plugin add cordova-plugin-crosswalk-webview

Hope that helps :)

Arxi commented 7 years ago

@gkimpson ah yes, now I remember using crosswalk on another app. Unfortunately, crosswalk adds significant overhead in terms of app size. But I don't see any other option, except for maybe implementing the ability to take a photo via cordova-plugin-camera myself.

Thank you again!

gine commented 6 years ago

I have exactly the same problem. Had someone solve it without crosswalk?

gine commented 6 years ago

@gkimpson @Arxi With Cordova 7.0 on my app i can open the camera and take a picture but when i confirm the picture it doesn't upload picture anymore. Any other have this problem? Some solotions?

I have the problems only on an android 7.0, with cordova 6.3.0 too. I have tried with ngf-capure too.

Arxi commented 6 years ago

@gine I stopped using ng-file-upload for taking pictures and now use it only for selecting pictures from disk. For taking pictures, I use cordova-plugin-camera. So unfortunately I always have to show two buttons to the user: "Select photo" using ng-file-upload and "Take photo" using cordova-plugin-camera.

I use Cordova 6.4.0.