我正在尝试在一个非常简单的手机间隙应用中测试条形码扫描仪。我正在尝试在PhoneGap Developer App中测试该应用程序。我一直在关注谷歌搜索时发现的一系列不同的解决方案:
http://www.raymondcamden.com/2014/3/5/Barcode-Scanner-sample-and-new-repo-for-Cordova-examples
https://stackoverflow.com/a/19591607/418549
这是我的HTML:
<div class="app">
<h1>PhoneGap</h1>
<div id="deviceready" class="blink">
<p class="event listening">Connecting to Device</p>
<p class="event received">Device is Ready</p>
</div>
<p></p>
<p></p>
<button id="startScan">Start Scan</button>
<div id="results"></div>
</div>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/barcodescanner.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript">
app.initialize();
</script>
这是我的初始化代码:
var resultDiv;
var app =
{
// Application Constructor
initialize: function ()
{
this.bindEvents();
},
bindEvents: function ()
{
document.addEventListener('deviceready', this.onDeviceReady, false);
},
onDeviceReady: function ()
{
app.receivedEvent('deviceready');
document.querySelector("#startScan").addEventListener("touchend", startScan, false);
resultDiv = document.querySelector("#results");
},
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);
}
};
function startScan()
{
try
{
var scanner = cordova.require("com.phonegap.plugins.barcodescanner.BarcodeScanner");
//var scanner = cordova.require("cordova/plugin/BarcodeScanner");
scanner.scan(
function (result)
{
var s = "Result: " + result.text + "<br/>" +
"Format: " + result.format + "<br/>" +
"Cancelled: " + result.cancelled;
resultDiv.innerHTML = s;
},
function (error)
{
alert("Scanning failed: " + error);
}
);
}
catch (e)
{
console.log('-------------------------- ERROR 1');
console.log(e);
}
}
在PhoneGap Build App中运行此代码时,我总是收到'module com.phonegap.plugins.barcodescanner.BarcodeScanner not found'错误消息。我认为问题是Java文件没有加载。
PhoneGap Developer App指向根www文件夹。它应该指向Android的www文件夹吗?
由于
汤姆