0

I am trying to access Cordova's camera plugin from my Mobile Angular UI project.

navigator.geolocation is working find along with all of the other Cordova stuff but when I try to access navigoator.camera it comes back as undefined.

When I console.log(navigator) camera is not included:

Screenshot of navigator output

The plugin was installed with the following command and it is in my plugins folder:

cordova plugin add cordova-plugin-camera

enter image description here

I'm currently trying to access it with a factory like this:

angular.module('App.services.Camera', [
  'App.services.Cordova'
])

.factory('openCamera', function(deviceReady, $document, $window, $rootScope){
  return function(done) {
    deviceReady(function() {
      var srcType = Camera.PictureSourceType.CAMERA;
      var options = setOptions(srcType);
      var func = createNewFileEntry;
      navigator.camera.getPicture(function cameraSuccess(imageUri) {
        $rootScope.$apply(function(){
          done(imageUri);
        });
        displayImage(imageUri);
        func(imageUri);
      }, function cameraError(error) {
          console.debug("Unable to obtain picture: " + error, "app");

      }, options);
    });
  };
});

Do I need to reference the plugin somewhere to add it to my project or am I installing the plugin the wrong way?

wtmcm
  • 307
  • 1
  • 4
  • 19
  • 1
    You might find it easier to use [ngCordova](http://ngcordova.com) if you want to do that. Also, are you trying it in the browser? That won't work - it will only actually work on a mobile device. – Matthew Daly Dec 08 '16 at 22:32
  • I had only made it as far as the emulator which didn't work either obviously. Do you know if there is a way to test in browser? Testing on a device will be very time consuming in comparison. – wtmcm Dec 09 '16 at 08:57
  • No, there isn't. I use Phonegap Build, which builds the app on Adobe's servers, and generally I can get a new build up and running in a few minutes. iOS takes longer to set up than Android. – Matthew Daly Dec 09 '16 at 09:13
  • You could write a unit test and mock the dependency. That's about it in terms of testing it locally. – Matthew Daly Dec 09 '16 at 09:14

1 Answers1

1

Quick checklist.

  • Do you add the plug-in in the config. xml? (if not, added. This will review in each build if the plug-ins were installed for the platform)

  • Do you test in a real device? Plug-in will not work on browsers (this is what I think happened, so please run on device: ionic run android )

jjdltc
  • 136
  • 1
  • 8