samedi 31 janvier 2015

Cordova- taking picture


so I'm still pretty new to cordova and right now, I'm using it to make an app and I'm trying to take a picture and then save it. Right now, I can't take a picture. All I have is a button and in the corresponding javascript file, a function is called when the button is pressed. I started off by running 'cordova plugin add org.apache.cordova.camera'. This is what I tried:



document.addEventListener("deviceready', onDeviceReady);

function onDeviceReady() {

$('#picture').on('click',function() {
takePicture();
}

function takePicture() {

if (!navigator.camera) {
alert("Camera API not supported", "Error");
return;
}

navigator.camera.getPicture(function(imageURI) {
alert("test");
}, function(err) {
alert("Inside err");
}, cameraOption);

/*navigator.camera.getPicture(function(imagePath) {
alert("test");
document.getElementByID("photoImg").setAttribute("src", imagePath);
alert("Got picture");
}, function() {
alert("Photo canceled");
}, {
destinationType: navigator.camera.DestinatonType.FILE_URI
});*/


}
}


I got the function from http://ift.tt/14zMPw5 and I also tried the second from another place, but the camera doesn't come up in either one. Also, I inserted some alerts inside and none of them appear, so I'm a bit confused.


Does anyone have any suggestions how I can get the camera to show up?





Aucun commentaire:

Enregistrer un commentaire