我是Phonegap的新手,在我的应用程序中我必须扫描条形码,所以我使用了以下.js文件进行扫描。这个js文件是从HTML页面调用的。在iOS中它工作正常,但在android中它只扫描偶数时间,奇怪的是它不扫描条形码。任何人都可以解决这个问题吗?
var app = {
initialize: function() {
this.bindEvents();
},
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
document.getElementById('scan').addEventListener('click', this.scan, false);
},
onDeviceReady: function() {
app.receivedEvent('deviceready');
},
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;');
},
scan: function() {
var scanner = cordova.require("cordova/plugin/BarcodeScanner");
scanner.scan(function(result) {
window.location.href = "scan?id=" + result.text;
}, function(error) {
alert("scan function error");
console.log("Scanning failed: ", error);
});
}
};
答案 0 :(得分:0)
我有同样的问题。我刚刚在config.xml中添加了下一行,它开始工作正常。
<preference name="phonegap-version" value="3.3.0" />