2014-10-20 83 views
0

上午我試圖在Android上設置一個條形碼應用程序,並且卡住了。相機條形碼功能是無用的,並且能夠捕捉條形碼,但是之後沒有任何反應。成功/失敗的回調似乎根本不會被調用。下面是我的代碼科爾多瓦Android條碼回調不起作用

<script type="text/javascript" charset="utf-8" src="cordova.js"></script> 
<script type="text/javascript" src="camera.js"></script> 
<script type="text/javascript" src="barcodescanner.js"></script> 
<script type="text/javascript" src="childbrowser.js"></script> 
<script src="resources/js/barcoding.js" type="text/javascript" charset="utf-8"></script> 

</head> 

<body class="home"> 
<div class="container"> 
     <div class="containerLogin"> 
       <header class="header"><img src="resources/images/logo.png" width="285" height="71" alt="Autopic" /></header> 
     </div> 
     <div class="containerMain"> 
       <h1>Welcome back <span id="name"></span></h1> 
       <ul> 
         <li><span class="picture"></span><a href="" id="scan">Scan barcode</a></li> 
         <li><span class="picture"></span><a href="viewpics.html">View pictures</a></li> 
         <li> 
          <select id="searchtype" onchange="getInput(this.value)" > 
            <option selected="selected" value="">Search Vehicles By</option> 
            <option value="1">VIN</option> 
            <option value="2">Registration Number</option> 
          </select> 
         </li> 
         <li class="inputselectvin"><input type="text" placeholder="Search by VIN" class="defaultinput full searchbyvin"/></li> 
         <li class="inputselectreg"><input type="text" placeholder="Search by Registration" class="defaultinput full searchbyreg"/></li> 
         <li class="viewvehicle"> 
         <button onclick="capturePhoto(); return false;" class="btnRed fleft" >TAKE A PICTURE</button> 
         <img style="display:none;width:60px;height:60px;" id="smallImage" src="" /> 


         </li> 
       </ul> 
       <div id="deviceready" class="blink"> 
        <p class="event listening">Connecting to Device</p> 
        <p class="event received">Device is Ready</p> 
       </div> 
        <p id="info"></p> 
     </div> 

下面是barcoding.js

var app = { 
// Application Constructor 
initialize: function() { 
    this.bindEvents(); 
}, 
// Bind Event Listeners 
// 
// Bind any events that are required on startup. Common events are: 
// `load`, `deviceready`, `offline`, and `online`. 
bindEvents: function() { 
    document.addEventListener('deviceready', this.onDeviceReady, false); 
    document.getElementById('scan').addEventListener('click', this.scan, false); 
    document.getElementById('encode').addEventListener('click', this.encode, false); 
}, 

// deviceready Event Handler 
// 
// The scope of `this` is the event. In order to call the `receivedEvent` 
// function, we must explicity call `app.receivedEvent(...);` 
onDeviceReady: function() { 
    app.receivedEvent('deviceready'); 
}, 

// Update DOM on a Received Event 
receivedEvent: function(id) { 
    var parentElement = document.getElementById(id); 
    var listeningElement = parentElement.querySelector('.listening'); 
    var receivedElement = parentElement.querySelector('.received'); 

    listeningElement.setAttribute('style', 'display:none;'); 
    receivedElement.setAttribute('style', 'display:block;'); 

    console.log('Received Event: ' + id); 
}, 

scan: function() { 
    cordova.plugins.barcodeScanner.scan(
     function (result) { 
      alert("We got a barcode\n" + 
       "Result: " + result.text + "\n" + 
       "Format: " + result.format + "\n" + 
       "Cancelled: " + result.cancelled); 
     }, 
     function (error) { 
      alert("Scanning failed: " + error); 
     } 
    );  
}, 
}; 

任何想法,對什麼錯的內容?一直在這工作幾個小時,並得到沒有哪裏

回答

0

也許你必須刪除這個逗號嗎?

scan: function() { 
     cordova.plugins.barcodeScanner.scan(
      function (result) { 
       alert("We got a barcode\n" + 
        "Result: " + result.text + "\n" + 
        "Format: " + result.format + "\n" + 
        "Cancelled: " + result.cancelled); 
      }, 
      function (error) { 
       alert("Scanning failed: " + error); 
      } 
     );  
    }, <---------------------------- This comma 
    };