Use camera for both native and web app with Ionic/AngularJS and Cordova


#1

I’m trying to use the Camera, and I would like to know if you have any exemple on how to make it work on both web / native.

I have this piece of code, borrowed from the ng-cordova doc :

    $scope.takePicture = function() {
        var options = {
            quality: 75,
            destinationType: Camera.DestinationType.DATA_URL,
            sourceType: Camera.PictureSourceType.CAMERA,
            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
        });
    }

When I use it, it works well with my device, but catch an error with the web version

ReferenceError: Camera is not defined

That’s why I ask if you have any good way to do that. I could simulate a click on an hidden input, but it doesn’t look pretty. If you have any idea :slight_smile:


#2

Hi, $cordovaCamera relies on the navigator.camera object exposed by the org.apache.cordova.camera plugin, so it’ll only work when running native.


#3

Hi,

Thanks for your answer, that’s what I thought too. Too bad ! :slight_smile: