bitpay / cordova-plugin-qrscanner

A fast, energy efficient, highly-configurable QR code scanner for Cordova apps and the browser.
MIT License
567 stars 773 forks source link

Skeleton app not working at all #370

Closed CarbonMan closed 2 years ago

CarbonMan commented 2 years ago

index.html <!DOCTYPE html>

<html>
<head>
    <meta charset="utf-8">
    <link rel="stylesheet" href="css/index.css">
    <title>Hello World</title>
</head>
<body>
    <button id="scan">SCAN</button>
    <script src="cordova.js"></script>
    <script src="js/index.js"></script>
</body>
</html>

index.css

html, body, ion-app, ion-content, ion-page, .nav-decor{
    background-color: transparent !important;
}

index.js

document.addEventListener('deviceready', onDeviceReady, false);

function onDeviceReady() {
QRScanner.prepare(onDone);

function onDone(err, status) {
    if (err) {
        console.error(err);
    }
    console.log(status);
    if (status.authorized) {
        console.log('Authorized');
    } else if (status.denied) {
        console.log('Denied');
    } else {
        console.log('Denied 2');
    }
}

document.getElementById("scan").onclick = ()=>{
    QRScanner.scan(displayContents);

    function displayContents(err, text){
      if(err){
          console.error(err);
      } else {
        alert(text);
      }
    }
    QRScanner.show(function(status){
     console.log(status);
   });
};
}

Console displays "Authorized", the screen goes black when the button is clicked. onclick code is called but, displayContents is never called.

The status callback from the show() function seems ok. I have used the camera on this device within a Cordova app to take stills so it is possible to access the camera.

Using Cordova Android 9.1.0

CarbonMan commented 2 years ago

Turned out to be a hardware issue. The device was a PDA with an inbuilt scanner. Enabling the scanner through O/S software caused the problem.