Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zxing Barcode scanner plugin for phonegap android not working on nexus 7 which is having only front camera

Which Barcode scanner plugin for phonegap android is working for front camera also?

like image 871
user2452045 Avatar asked Jun 04 '13 13:06

user2452045


1 Answers

To make the Cordova/PhoneGap BarcodeScanner plugin work you need to go a bit further than you would with most of the other plugins.

I do most of my work outside Eclipse, so I'll explain how this is done from the Terminal and I'll add on Eclipse notes, if you need them (just ask.)

Clone the plugins project

If you haven't already, grab the phonegap-plugins project from github:

git clone git://github.com/phonegap/phonegap-plugins.git 

(We'll assume they are cloned into: /home/mike/phonegap-plugins)

Also let's assume your project is called /home/mike/CordovaProject for the purposes of this answer.

and then copy the contents of /home/mike/phonegap-plugins/Android/BarcodeScanner/2.2.0/LibraryProject into /home/mike/BarcodeLibrary

This will contain the zxing library project as a usable activity, check that you have AndroidManifest.xml, ant.properties, assets, bin... etc. inside /home/mike/BarcodeLibrary.

I've checked this with a Nexus 7, the zxing library code contained in the plugin is working ok. (Which is zxing 2.1 not 2.2)

It's possible to replace the zxing library code at src/com/google/zxing... with the code from the 2.2 download, but it's unnecessary and will require additional work / testing.

Update the library to use Android SDK

You will need to update the /home/mike/BarcodeLibrary project use

android update project /home/mike/BarcodeLibrary

If you need to specify a target (SDK version) you can get a list doing: android list target

By the way this assumes you have the android sdk installed. Get it from http://developer.android.com/sdk/

If something has gone wrong, make sure you've copied the contents of LibraryProject into BarcodeLibrary

Update your project

Now you can update your project to use the BarcodeLibrary. Copy these into your project:

phonegap-plugins/Android/BarcodeScanner/2.2.0/assets/www/barcodescanner.js
phonegap-plugins/Android/BarcodeScanner/2.2.0/src/com/phonegap/plugins/barcodescanner/BarcodeScanner.java

into assets/www and src/com/phonegap/plugins/barcodescanner respectively.

Project Properties / Library References

Now you need to update the project.properties to include the BarcodeLibrary, edit it to include the new line:

android.library.reference.1=../BarodeLibrary/

(if you had more libraries to reference, you'd number them, to allow ordering for compilation dependencies.)

Note, if you wanted to include the library directly into your main project, you can just copy it into a folder, eg. /home/mike/BarcodeLibrary/external/BarcodeLibrary

The reference would then be:

android.library.reference.1=external/BarodeLibrary/

That's up to you, leaving it in the adjacent folder makes it easy to reuse, and maintain separately. Placing it in the project itself can simplify version control and continuous integration.

Update AndroidManifest

You now need to update your AndroidManifest.xml

Permissions

Add these permission to <manifest> if they're not already included:

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.FLASHLIGHT" />

Features

Add these features to <manifest> if they're not already included:

<uses-feature android:name="android.hardware.camera" android:required="false"/>
<uses-feature android:name="android.hardware.camera.front" android:required="false"/>
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false"/>
<uses-feature android:name="android.hardware.camera.flash" android:required="false"/>

Barcode Activity Node

Add this activity node inside <application> at the bottom.

<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"
            android:exported="false">
  <intent-filter>
    <action android:name="com.phonegap.plugins.barcodescanner.SCAN"/>
    <category android:name="android.intent.category.DEFAULT"/>
  </intent-filter>
</activity>

Config.xml

The res/config.xml for the project will need the barcode plugin specified. Simply add the following line to the plugins node.

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

Done...

You should be able to go ahead and build the project:

ant debug

Or

cordova/run
like image 104
ocodo Avatar answered Nov 13 '22 13:11

ocodo