Inkers
Inkers

Reputation: 219

Camera and PictureSourceType not defined Phonegap

I am trying to get the camera working from a button but am getting errors on the commented lines below. I am using the documentation provided by Phonegap/Cordova (v2.1). Any help appreciated.

    var pictureSource = navigator.Camera.PictureSourceType.CAMERA; // Cannot read PictureSourceType of undef
    var destinationType = navigator.camera.DestinationType.FILE_URI;

    function onPhotoURISuccess(imageURI) {
        var placeImage = document.getElementById('placeImage');
        placeImage.src = imageURI;
        placeImage.style.display = 'block';
        console.log(imageURI);
    }

    function getPhoto() {
        navigator.Camera.getPicture(onPhotoURISuccess, onFail, { //I am getting an error for this line saying camera is not defined?
             quality: 50, 
             destinationType: camera.destinationType.FILE_URI,
             sourceType: pictureSource
        });
    }

    function onFail(message) {
        alert('Failed because: ' + message);
    }

Upvotes: 0

Views: 4143

Answers (2)

Jie
Jie

Reputation: 317

I am also working on this. If you are talking about Android, you need to test on a real device. No matter you test on browser or simulator in Eclipse, it will give you Camera not defined error. I guess it is because hardware problem.

Upvotes: 0

Simon MacDonald
Simon MacDonald

Reputation: 23273

Make sure you've got "deviceready" event first. For your call to getPicture() do this:

navigator.Camera.getPicture(onPhotoURISuccess, onFail, {
         quality: 50, 
         destinationType: navigator.camera.DestinationType.FILE_URI,
         sourceType: pictureSource
    });

Upvotes: 2

Related Questions