整合Jquery mobile和phonegap以访问摄像头
我正在尝试将带有Phonegap的HTML5 Jquery移动应用程序集成到访问摄像头以扫描条形码,但我没有找到任何使用phonegap访问摄像头的示例。
我尝试了一个关于“http://docs.phonegap.com/en/1.0.0/phonegap_camera_camera.md.html”的例子,但它给navigator.camera是未定义的。
在你的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);
}
链接地址: http://www.djcxy.com/p/61925.html
上一篇: Integration of Jquery mobile with phonegap to access camera
下一篇: Phonegap + jQuery Mobile, real world sample or tutorial