Integration of Jquery mobile with phonegap to access camera
I am trying to integrate HTML5 Jquery mobile application with Phonegap to access camera for scanning of barcode but I did not find any example to access camera with phonegap.
I tried an example on "http://docs.phonegap.com/en/1.0.0/phonegap_camera_camera.md.html" but it gives navigator.camera is undefined.
In your HTML file put this:
<a href="#" onClick="captureImage();" data-role="button">Take a picture</a>
And in your JS put this:
function captureImage(){
//SET LIMIT TO THE NUMBER OF PICTURES YOU WANT TO CAPTURE AT ONCE
navigator.device.capture.captureImage(captureImageSuccess, captureError, {limit: 1});
}
//ON CAPTURE SUCCESS
function captureImageSuccess(mediaFiles) {
var i, len;
var formatSuccess = function (mediaFile) {
//DO SOMETHING ON SUCCESS
};
//IF YOU ARE CAPTURING MULTIPLE FILES
for (i = 0, len = mediaFiles.length; i < len; i += 1) {
mediaFiles[i].getFormatData(formatSuccess, formatError);
console.log("path: " + mediaFiles[i].fullPath);
console.log("path: " + mediaFiles[i].name);
//DO SOMETHING WITH THE CAPTURED FILES
}
console.log("captureImageSuccess");
}
//error functions
function captureError(error) {
var msg = 'An error occurred during capture: ' + error.code;
navigator.notification.alert(msg, null, '');
}
function formatError(error) {
alert("Error getting file format data: " + error.code);
}
链接地址: http://www.djcxy.com/p/61926.html
上一篇: 正确的使用JQuery的方式