Skip to content

Instantly share code, notes, and snippets.

@dhavaln
Created July 5, 2012 08:54
Show Gist options
  • Save dhavaln/3052428 to your computer and use it in GitHub Desktop.
Save dhavaln/3052428 to your computer and use it in GitHub Desktop.
Cordova 1.7 Camera Test
<!DOCTYPE html>
<html>
<head>
<title>Capture Photo</title>
<script type="text/javascript" charset="utf-8" src="lib/android/cordova-1.7.0.js"></script>
<script type="text/javascript" charset="utf-8">
function onLoad() {
var pictureSource;
var destinationType;
var deviceReady = false;
alert("JS1 Loaded!")
document.addEventListener("deviceready", onDeviceReady, false);
}
function onDeviceReady() {
alert("Device ready!");
deviceReady = true;
pictureSource = navigator.camera.PictureSourceType;
destinationType = navigator.camera.DestinationType;
document.addEventListener("resume", onResume, false);
}
function onResume() {
alert("Device resumed!");
}
function takePicture() {
if (!deviceReady) {
alert("Error: PhoneGap did not initialize.");
}
navigator.camera.getPicture(
function(uri) {
var img = document.getElementById('camera_image');
img.style.visibility = "visible";
img.style.display = "block";
img.src = uri;
document.getElementById('camera_status').innerHTML = "Success";
},
function(e) {
console.log("Error getting picture: " + e);
document.getElementById('camera_status').innerHTML = "Error getting picture.";
}, {
quality : 50,
destinationType : destinationType.DATA_URI
});
};
</script>
</head>
<body onload="onLoad()">
<button onclick="takePicture();">Capture Photo</button> <br>
<img style="width:100px;height:100px;" id="camera_image" src="" />
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment