We are using ngCordova and I have $cordovaCamera injected into my method. I get errors when using the Camera object in my camera options:
// select an existing picture
$scope.selectPicture = function($cordovaCamera) {
var options = {
//quality : 75,
destinationType : Camera.DestinationType.DATA_URL,
sourceType : Camera.PictureSourceType.PHOTOLIBRARY,
allowEdit : true,
encodingType: Camera.EncodingType.JPEG,
//targetWidth: 100,
//targetHeight: 100,
popoverOptions: CameraPopoverOptions,
saveToPhotoAlbum: false
};
$cordovaCamera.getPicture(options).then(function(imageData) {
// success image data is here
}, function(err) {
// An error occured. Show a message to the user
});
};
The error Im seeing is:
ReferenceError: Camera is not defined
at Scope.$scope.takePicture (file:///android_asset/www/js/controllers.js:272:22)
at file:///android_asset/www/lib/ionic/js/ionic.bundle.js:18471:21
at file:///android_asset/www/lib/ionic/js/ionic.bundle.js:43026:9
at Scope.$eval (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:20326:28)
at Scope.$apply (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:20424:23)
at HTMLAnchorElement. (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:43025:13)
at file:///android_asset/www/lib/ionic/js/ionic.bundle.js:10478:10
at forEach (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:7950:18)
at HTMLAnchorElement.eventHandler (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:10477:5)
at triggerMouseEvent (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:2648:7)
Line 272 is the first line of options in the code fragment up top.
Make sure you try to access the camera only after the $ionicPlatform.ready() or onDeviceReady() has triggered. Many plugins are not loaded instantly which believe youāre suffering from.
The problem was that the actual plugin never made it into the actual Android build even though it had been installed and existed in my plugins folder. Furthermore, telling cordova to install again doesnāt work. I had to remove my platforms, remove the plugin, reinstall the plugin, re-add my platform (I have a hooks script that fires after platform add that installs all the plugins we use). Only after all, my Android build actually worked.
I had a similar problem with code similar to yours. The problem was solved only after I updated my phone. I was disappointed for not getting the method getPicture() working and I give up on trying to fix this bug for like 1 week. Then, my cellphone (android) was updated and right after the update process I checked the app and it was working.
I have to mention that I almost throw my cellphone away --ā
Iām still having a problem with wp8.1, firtst i got this error to,but now the camera shows up when i tab to make a picture i hear a clicking sound like the picture is taken but after that nothing happens and the only thing i can do is cancel the camera
I am running the app in a real device, I am using chrome console to debug and type āwindow.cordovaā or even āCameraā on chromeās console and the result was undefined which means that cordova wasnāt loaded correctly.
Then Iāve noticed that in my index.html I removed the call to:
<script src="cordova.js"></script>
Iāve just added the piece of code above and now my code is like this:
Iāve tried to do what was advices, and this didnāt help me at all. When testing in a browser, Iām still getting the error: āReferenceError: Camera is not definedā, and when testing on a device (iOS) the camera opens, takes a photo and doesnāt add it to the App nor Firebase. I also donāt know how to debug it from that point onwards. So I canāt tell weather the problem is with Cordova or with the rest of my code that interfaces with Firebase. Any advice on how to debug?
Hi! Iāve same problem. Browserās console show me same error and i thought this was due by service, it mean, i create a service that contain āCameraā (Here code):
.service(āCameraā, function($q) {
return {
getPicture: function(options) {
var q = $q.defer();