0

我正在尝试将 HTML5 Jquery 移动应用程序与 Phonegap 集成以访问相机以扫描条形码,但我没有找到任何使用 phonegap 访问相机的示例。

我在“http://docs.phonegap.com/en/1.0.0/phonegap_camera_camera.md.html”上尝试了一个示例,但它给出了 navigator.camera 未定义。

4

1 回答 1

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); 
}
于 2013-03-03T11:21:09.043 回答