我试图在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 :(得分: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
};