Umer Pasha Blogs

Simplest Phonegap Barcode reader example

on August 27, 2014

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.




  1. To add the plugin , in Config.xml you need to have:

<gap:plugin name=”com.phonegap.plugins.barcodescanner”/>


  1. 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 + "&lt;br/&gt;" +</p><p>                                               "Format: " + result.format + "&lt;br/&gt;" +</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>







7 responses to “Simplest Phonegap Barcode reader example

  1. H See says:

    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.

  2. arvind says:

    Thank you very much. your code is perfectly working.
    i added some code in config.xml file

    after then only its work fine.

  3. Ravinder says:

    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.

  4. Ravinder says:

    please reply me sir

  5. Please help me regarding phonegap barcode.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: