Zxing barcode scanner plugin for an Android phone not running on Nexus 7 that only has a front camera

Which barcode scanner plugin for Android phone for mobile phone works for front camera?

+6
source share
1 answer

To make the Cordova / PhoneGap BarcodeScanner plugin, you need to go a little further than with most other plugins.

I do most of my work outside of Eclipse, so I will explain how to do this from the terminal, and I will add Eclipse notes if you need them (just ask.)

Clone plugin project

If you havenโ€™t already done so, take the phonegap-plugins project from github:

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

(We will assume that they are cloned into: /home/mike/phonegap-plugins )

Also suppose your project is called /home/mike/CordovaProject for the purpose of this answer.

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

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

I checked this with Nexus 7, the zxing library code contained in the plugin works fine. (What zxing 2.1 is not 2.2)

It is possible to replace the zxing library code with src/com/google/zxing... code from download 2.2, but it is not needed and will require additional work / testing.

Update library to use Android SDK

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

 android update project /home/mike/BarcodeLibrary 

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

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

If something went wrong, make sure you copy the contents of LibraryProject to BarcodeLibrary

Refresh Project

Now you can update your project to use BarcodeLibrary . Copy them 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 

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

Project Properties / Library Links

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

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

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

Note. If you want to include the library directly in your main project, you can simply copy it to a folder, for example. /home/mike/BarcodeLibrary/external/BarcodeLibrary

The link will then be:

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

It is up to you, leaving it in a nearby folder, which simplifies reuse and is supported separately. Placing it in the project itself can simplify version control and continuous integration.

Update AndroidManifest

Now you need to update AndroidManifest.xml

Permissions

Add these permissions to <manifest> if they are not already included:

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

Features

Add these functions to <manifest> if they are 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"/> 

Node Barcode Activity

Add this node activity inside the <application> below.

 <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

Res / config.xml for the project will require a barcode plugin. Just 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 a project:

 ant debug 

or

 cordova/run 
+9
source

Source: https://habr.com/ru/post/946506/


All Articles