title: Setting up zxing 2.0 barcode scanner in android app
body: <p>I am trying to setup barcode scanner for an android app. I was able to setup the barcode scanner using the plugin provided by phonegap. That worked fine on some phones but was not working on some HTC phones. I searched online and some one suggested that upgrading to zxing 2.0 should solve the problem. So, I downloaded the zxing-2.0 and followed the following steps:
  1. Unzipped the zxing-2.0 and built the core package.
  2. Added the android package to eclipse as an Android Project and selected it as library( named zxing-2 ).
  3. Added core.jar as an external jar to the zxing-2 which made it build successfully on eclipse.
  4. Added the zxing-2 as project dependency of my main app(myApp). Also added core.jar as an external jar in myApp.</p>
  
  <p>MyApp's mainfest.xml now contains( earlier it contained the action name as com.phonegap.plugins.barcodescanner.SCAN):</p>
  
  <pre><code>&lt;activity android:name="com.google.zxing.client.android.CaptureActivity"
                android:screenOrientation="landscape"
                android:configChanges="orientation|keyboardHidden"
                android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
                android:windowSoftInputMode="stateAlwaysHidden"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="com.google.zxing.client.android.SCAN"/&gt;
              &lt;category android:name="android.intent.category.DEFAULT"/&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
  
      &lt;activity android:name="com.google.zxing.client.android.encode.EncodeActivity" 
                android:label="@string/share_name"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="com.google.zxing.client.android.ENCODE"/&gt;
              &lt;category android:name="android.intent.category.DEFAULT"/&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
  </code></pre>
  
  <p>I am using the BarcodeScanner.java provided in phone gap plugin to invoke the barcode scanner. I changed the scan() method in it to:</p>
  
  <pre><code>//new version
  public void scan() {
      Intent intentScan = new Intent("com.google.zxing.client.android.SCAN");
      intentScan.addCategory(Intent.CATEGORY_DEFAULT);
  
      this.ctx.startActivityForResult((Plugin) this, intentScan, REQUEST_CODE);
  }
  
  //earlier version(it worked with zxing 1.7)
  public void scan() {
      Intent intentScan = new Intent("com.phonegap.plugins.barcodescanner.SCAN");
      intentScan.addCategory(Intent.CATEGORY_DEFAULT);
  
      this.ctx.startActivityForResult((Plugin) this, intentScan, REQUEST_CODE);
  }
  </code></pre>
  
  <p>The project builds fine but when I run it and trigger the scan, I get the following runtime exception:</p>
  
  <pre><code>03-03 19:43:13.499: E/AndroidRuntime(276): FATAL EXCEPTION: main
  03-03 19:43:13.499: E/AndroidRuntime(276): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.phonegap.myApp/com.google.zxing.client.android.CaptureActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class phonegap
  03-03 19:43:13.499: E/AndroidRuntime(276):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
  03-03 19:43:13.499: E/AndroidRuntime(276):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
  03-03 19:43:13.499: E/AndroidRuntime(276):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
  03-03 19:43:13.499: E/AndroidRuntime(276):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
  03-03 19:43:13.499: E/AndroidRuntime(276):  at android.os.Handler.dispatchMessage(Handler.java:99)
  03-03 19:43:13.499: E/AndroidRuntime(276):  at android.os.Looper.loop(Looper.java:123)
  03-03 19:43:13.499: E/AndroidRuntime(276):  at android.app.ActivityThread.main(ActivityThread.java:4627)
  03-03 19:43:13.499: E/AndroidRuntime(276):  at java.lang.reflect.Method.invokeNative(Native Method)
  03-03 19:43:13.499: E/AndroidRuntime(276):  at java.lang.reflect.Method.invoke(Method.java:521)
  03-03 19:43:13.499: E/AndroidRuntime(276):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
  03-03 19:43:13.499: E/AndroidRuntime(276):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
  03-03 19:43:13.499: E/AndroidRuntime(276):  at dalvik.system.NativeStart.main(Native Method)
  03-03 19:43:13.499: E/AndroidRuntime(276): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class phonegap
  03-03 19:43:13.499: E/AndroidRuntime(276):  at android.preference.GenericInflater.createItemFromTag(GenericInflater.java:441)
  03-03 19:43:13.499: E/AndroidRuntime(276):  at android.preference.GenericInflater.inflate(GenericInflater.java:317)
  03-03 19:43:13.499: E/AndroidRuntime(276):  at android.preference.GenericInflater.inflate(GenericInflater.java:263)
  03-03 19:43:13.499: E/AndroidRuntime(276):  at android.preference.PreferenceManager.inflateFromResource(PreferenceManager.java:251)
  03-03 19:43:13.499: E/AndroidRuntime(276):  at android.preference.PreferenceManager.setDefaultValues(PreferenceManager.java:444)
  03-03 19:43:13.499: E/AndroidRuntime(276):  at android.preference.PreferenceManager.setDefaultValues(PreferenceManager.java:422)
  03-03 19:43:13.499: E/AndroidRuntime(276):  at com.google.zxing.client.android.CaptureActivity.onCreate(CaptureActivity.java:167)
  03-03 19:43:13.499: E/AndroidRuntime(276):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
  03-03 19:43:13.499: E/AndroidRuntime(276):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
  03-03 19:43:13.499: E/AndroidRuntime(276):  ... 11 more
  03-03 19:43:13.499: E/AndroidRuntime(276): Caused by: java.lang.ClassNotFoundException: android.preference.phonegap in loader dalvik.system.PathClassLoader[/data/app/com.phonegap.myApp-1.apk]
  03-03 19:43:13.499: E/AndroidRuntime(276):  at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
  03-03 19:43:13.499: E/AndroidRuntime(276):  at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
  03-03 19:43:13.499: E/AndroidRuntime(276):  at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
  03-03 19:43:13.499: E/AndroidRuntime(276):  at android.preference.GenericInflater.createItem(GenericInflater.java:375)
  03-03 19:43:13.499: E/AndroidRuntime(276):  at android.preference.GenericInflater.onCreateItem(GenericInflater.java:417)
  03-03 19:43:13.499: E/AndroidRuntime(276):  at android.preference.GenericInflater.createItemFromTag(GenericInflater.java:428)
  03-03 19:43:13.499: E/AndroidRuntime(276):  ... 19 more
  </code></pre>
  
  <p>Can someone help me figure out what I am doing wrong here or have I missed something.</p>
  
  <p>Thanks.</p>