Created a small app last night to read barcodes.
Nothing fancy. Just a button to invoke the barcode reader camera and then returns the barcode number along with the barcode standard.
You can get it here:
Checked on iPhone 5S and Android Kit Kat.
I am only using an html file and a js file along with the config.xml.
You can get the code from my github repository. You can remove the resource files from config.xml. I just got it from the base template.
https://github.com/genrex/PhonegapBarcode
Instructions:
- To add the plugin , in Config.xml you need to have:
<gap:plugin name=”com.phonegap.plugins.barcodescanner”/>
- Write the following javascript to listen for an event (button click) and then start the scanner
</p><p>var resultDiv;</p><p> </p><p>document.addEventListener("deviceready", init, false);</p><p>function init() {</p><p> document.querySelector("#startScan").addEventListener("touchend", startScan, false);</p><p> resultDiv = document.querySelector("#results");</p><p>}</p><p> </p><p>function startScan() {</p><p> </p><p> cordova.plugins.barcodeScanner.scan(</p><p> function(result) {</p><p> var s = "Result: " + result.text + "<br/>" +</p><p> "Format: " + result.format + "<br/>" +</p><p> "Cancelled: " + result.cancelled;</p><p> resultDiv.innerHTML = s;</p><p> },</p><p> function(error) {</p><p> alert("Scanning failed: " + error);</p><p> }</p><p> );</p><p> </p><p>}</p><p> </p><p>
hi, thanks for sharing. The apk you shared works very well on my Nexus 4, KitKat 4.4.4. But I try to develop the app on my own using phonegap CLI, I cannot get it working. When I press the Scan Barcode button, nothing happened. And the server log did not show any error. Have been trying out this for a week with different samples and approaches. Appreciate your advice please.Thank you.
https://www.dropbox.com/s/yyn6mukdlide6g4/barcodedemo.zip?dl=0
Hi,
Did you try the code as is from the git?
Hi,
Many Thanks for your reply. I have resolved the issue by adding the plugin via Cordova CLI.
cordova plugins add https://github.com/wildabeast/BarcodeScanner.git
Thank you very much. your code is perfectly working.
i added some code in config.xml file
after then only its work fine.
Hii Umer Pasha, Please help me regarding barcode scaner in phonegap app. Will install plugin and using this one code in app but is not working.
please reply me sir
Please help me regarding phonegap barcode.