2016-06-23 10 views
1

Ich beginne Phonegap und ich lerne viele Plugins in Phonegap, aber ich bleibe stecken, wenn ich QR-Scanner in Phonegap verwenden möchte. Gib mir irgendeine Lösung, wenn esWie scanne ich QR-Code in Phonegap

+0

Mit welchem ​​Problem sind Sie konfrontiert? –

Antwort

6

Haben Sie diesen QR-Code-Scan in meiner Cordova App vor einer Weile versucht. Ich hoffe, es sollte gut funktionieren. Der Code ist wie folgt:

index.html

<!DOCTYPE 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 Scanner</title> 
    </head> 
    <body>   
     <script type="text/javascript" src="cordova.js"></script> 
     <script type="text/javascript" src="js/jquery.js"></script> 
     <script type="text/javascript" src="js/app.js"></script> 
     Click scan button to scan the QR code: <input type="button" value="scan" name = "scan" id="scan"/> 
    </body> 
</html> 

app.js

$(document).ready(function() { 
    document.addEventListener("deviceready", onDeviceReady, false); 
}); 

function onDeviceReady() {  
    $('#scan').click(function() 
     { 
      cordova.plugins.barcodeScanner.scan(
      function (result) { 
       alert("We got a barcode\n" + 
        "Result: " + result.text + "\n" + 
        "Format: " + result.format + "\n" + 
        "Cancelled: " + result.cancelled);    
      }, 
      function (error) { 
       alert("Scanning failed: " + error); 
      }); 
     } 
    ); 
} 

Stellen Sie sicher, jQuery-Bibliothek js Datei und QR-Code-Scanner-Plugin von phonegap-plugin-barcodescanner link hinzufügen, um zu versuchen aus diesem Beispiel.

+0

Ich habe das benutzt du hast Recht. aber das Problem ist, dass, wenn ich diesen Code benutze und laufe es gibt mir eine Warnung, aber ich möchte die Kamera starten, wenn Skript ausführen und etwas scannen, d. h. QR-Code und Druckausgabe. Ich denke sein Barcodescanner oder ich vermisse etwas. Wie du erwähnt hast, habe ich das alles benutzt. –

+0

@AnujKumar Es nutzt natürlich Ihre Gerätekamera, um den QR-Code zu scannen. Wenn Sie die Funktionalität erweitern möchten, können Sie dies tun. Nicht sicher, was ist Ihre tatsächliche Funktionalität – Gandhi

+0

meine Funktionalität ist nur, wenn App ausgeführt wird, öffnen Sie nur die Kamera und QR scannen. –

Verwandte Themen