3

我正在使用 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.1.1 下的 Galaxy S3)上以横向模式启动此代码时,一切正常。当我以纵向模式启动此代码时,扫描栏结果永远不会返回,也不会出现错误消息。它只是回到 index.html,如果我重新启动扫描(横向)它可以工作。

所以我猜手机旋转和phonegap条形码插件存在错误。有人有解决方案吗?

4

0 回答 0