0

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.

TimoStaudinger
  • 41,396
  • 16
  • 88
  • 94
  • Is there any console output information? – gu mingfeng Jul 21 '16 at 02:03
  • @Franc It will obviously not work in browser. Did you tested it on device? Try this out - https://github.com/gandhirajan/Cordova_QR_Scanner – Gandhi Jul 21 '16 at 06:59
  • @Gandhi im testing it on the phonegap developer app, do you think thats the problem? thank you –  Jul 22 '16 at 16:05
  • @gumingfeng, theres not, thank you –  Jul 22 '16 at 16:07
  • @Gandhi ive copy the code you told me, it only sends me and alert when clicking the scan button saying "hi" –  Jul 22 '16 at 19:24
  • @Gandhi if i do "phonegap serve" and open it on the browser it gives me the same "hi" alert but then it opens a box, http://prntscr.com/bw9f37, if i build the apk using phonegap build, and download that apk on my android, it only shows me the alert when clicking the "scan", please i need help :(, also i added the plugin by doing "phonegap plugin add phonegap-plugin-barcodescanner" –  Jul 22 '16 at 19:32
  • now im getting an error which is " scanning failed:class not found" –  Jul 22 '16 at 21:31
  • @Franc I build using Cordova CLI. It obviously don't work on browser as you can't scan in browser. But building it as an apk and testing it on device should have worked. – Gandhi Jul 23 '16 at 03:16
  • @Franc suggest you to look at this link - http://stackoverflow.com/questions/37983058/how-to-scan-qr-code-in-phonegap where we dealt a similar issue – Gandhi Jul 23 '16 at 03:25

0 Answers0