Monday, September 24, 2012

Apache Cordova (Phonegap) and the BarcodeScanner Plugin for Android

Preface
This documentation relates to following versions:
Cordova 2.0.0

For one of my projects I have to use the BarcodeScanner Plugin for Android. I had some problems getting it to work so I describe what had to be done in detail.

Create a new Android Project
First I created a new Android Project called Testbarcode according to the following documentation:

http://docs.phonegap.com/en/2.0.0/guide_getting-started_android_index.md.html#Getting%20Started%20with%20Android

Import the LibProject
Then I imported the LibProject as seperate project and turned it in to a Library Project in the Eclipse application properties.

Use the LibProject in the Testbarcode Project
I added the LibProject in to my Testbarcode project according to the description but there are some differences.

The difference is that in newer versions the file in res/xml is not called plugins.xml anymore but config.xml. So the following line:

<plugin name="BarcodeScanner" value="com.phonegap.plugins.barcodescanner.BarcodeScanner"/>

has to be added to config.xml and not plugins.xml. I received a class not found error.

https://github.com/phonegap/phonegap-plugins/tree/master/Android/BarcodeScanner

Simon Mac Donald has described this on his blog:
http://simonmacdonald.blogspot.de/2012/07/updates-to-plugins-for-phonegap-200.html

Using the index.html from Simon Mac Donald for testing
I have used the example index.html from Simon Mac Donalds Blog and changed the js from phonegap-1.2.0.js to cordova-2.0.0.js.

http://simonmacdonald.blogspot.ch/2011/12/installing-barcode-plugin-for-phonegap.html

That was it. I could scan barcodes.

2 comments:

  1. This is a wonderful blog and I guess it will be helpful in getting understanding of barcode scanner plug in for android for many people.
    epos x

    ReplyDelete