Which Barcode scanner plugin for phonegap android is working for front camera also?
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.)
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.
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
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.
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.
You now need to update your AndroidManifest.xml
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" />
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"/>
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>
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>
You should be able to go ahead and build the project:
ant debug
Or
cordova/run
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With