javascript - Cordova Phonegap Barcode plugin won't launch from my Intel XDK app -
i have been building small app intel xdk. try open phonegap barcode scanner when launch button clicked nothing happens. goal scan qr code , open inappbrowser link containing result data. have both device (cordova-plugin-device) , barcode scanner (phonegap-plugin-barcodescanner) plugins installed permissions camera , flash.
here code:
<script type="text/javascript"> document.addeventlistener("deviceready", scannow, false); function scannow() { cordova.plugins.barcodescanner.scan( function (result) { // alert("we got barcode\n" + // "result: " + result.text + "\n" + // "format: " + result.format + "\n" + // "cancelled: " + result.cancelled); window.open("http://www.example.com?qr=" + result.text, '_system', 'location=no'); }, function (error) { alert("error: " + error); });} </script> and launch button:
<a role='button' onclick="scannow();">scan</a> edit: solved problem adding link dummy script index page head.
<script src="cordova.js"></script>
you don't need call scannow() function on deviceready event, need insure calls not happen until after deviceready event has fired. since you're debugging, change line like...
document.addeventlistener("deviceready", alertdeviceready, false); ...and add alertdeviceready() gives alert or console message. takes second or two, can take longer on slow devices or if you've got plugins require long init time.
this going security problem...
window.open("http://www.example.com?qr=" + result.text, '_system', 'location=no'); ...because should not open webview page (you're navigating away built-in webview app running inside of, you're not associated website).
you can use inappbrowser open alternate view on top of webview, advise use explictly named inappbrowser apis , not assume has been aliased use window.open() -- because have deprecated usage and, believe, not aliased in default installation anymore. is, try using...
cordova.inappbrowser.open() ...instead.
see docs here include details regarding current release plugin (which may work cli 5+ builds) , contains link github repo more information.
Comments
Post a Comment