QR scanner doesnt work with phonegap

486 Views Asked by At

I've started with Phonegap, I'm also using the Phonegap developer app in my iPhone to test apps, so I've tried every code sample I have found. However, none of them worked. Is there a problem when using Phonegap developer for testing barcode scanner?

This is my index.html:

<html>
<head>
    <meta charset="utf-8" />
    <meta name="format-detection" content="telephone=no" />
    <meta name="msapplication-tap-highlight" content="no" />
    <!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
    <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
    <link rel="stylesheet" type="text/css" href="css/index.css" />
    <title>qr app</title>
</head>
<body>
    <p>
        <button id="startScan">Start Scan</button>
    </p>

    <div id="results"></div>
    <script type="text/javascript" src="cordova.js"></script>
    <script type="text/javascript" src="js/index.js"></script>
</body>

This is my index.js:

var resultDiv;

document.addEventListener("deviceready", init, false);
function init() {
    document.querySelector("#startScan").addEventListener("touchend", startScan, false);
    resultDiv = document.querySelector("#results");
}

function startScan() {

    cordova.plugins.barcodeScanner.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);
        }
    );

}

I do add the plugin via Phonegap plugin add phonegap-plugin-barcodescanner, then I run phonegap serve and after opening it in the browser or in the Phonegap developer app nothing happens when I press the button.

0

There are 0 best solutions below