我正在使用PhoneGap 2.2.0和条形码插件https://github.com/phonegap/phonegap-plugins/tree/master/Android/BarcodeScanner(版本2.0.0)
这是index.html:
<!DOCTYPE HTML>
<html>
<head>
<title>Cordova</title>
<link rel="stylesheet" type="text/css" href="kkstyle.css" />
<script type="text/javascript" charset="utf-8" src="cordova-2.2.0.js"></script>
<script type="text/javascript" charset="utf-8" src="barcodescanner.js"></script>
<script type="text/javascript" charset="utf-8">
document.addEventListener("deviceready", onDeviceReady, onDeviceReadyFailed);
function onDeviceReady() {
}
function onDeviceReadyFailed() {
alert("device not ready");
}
function scanIt() {
window.plugins.barcodeScanner.scan(function(result) {
alert("We got a barcode\n" + "Result: " + result.text + "\n"
+ "Format: " + result.format + "\n" + "Cancelled: "
+ result.cancelled);
navigator.app.loadUrl("http://m.kelkoo.com/fr/search/"
+ result.text);
//http://m.kelkoo.com/fr/search/9782092610954
//window.location.href = "http://www.kelkoo.fr/ss-"+ result.text +".html";
}, function(error) {
alert("Scanning failed: " + error);
});
}
</script>
</head>
<body>
<div data-role="page">
<br><br><br>
<div id="camera">
<button class="camera-control" onclick="scanIt();">Scan</button>
<div style="text-align: center; margin: 20px;">
<img id="cameraPic" src="" style="width: auto; height: 120px;"></img>
</div>
</div>
</div>
</body>
</html>
当我在横向模式下在手机(4.5.1下的Galaxy S3)上启动此代码时,一切正常。当我以纵向模式启动此代码时,从不返回扫描栏结果,并且没有错误消息。它只是回到index.html,如果我启动一个新的时间扫描(在横向)它的工作。
所以我猜电话旋转有一个错误,并且插入了phonegap条形码。有人有解决方案吗?