我正在尝试将HTML5 Jquery移动应用程序与Phonegap集成以访问相机以扫描条形码,但我没有找到任何使用phonegap访问相机的示例。
我在" http://docs.phonegap.com/en/1.0.0/phonegap_camera_camera.md.html"上试了一个例子。但它给navigator.camera未定义。
答案 0 :(得分:0)
在你的HTML文件中输入:
<a href="#" onClick="captureImage();" data-role="button">Take a picture</a>
在你的JS中提出这个:
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);
}