-
This document explains to develop a Kony application which can read the linear barcodes and QR codes for Android platform.
-
The barcode scanner will be bundled within the Kony application, so the end-user need not require installing the barcode scanner explicitly.
-
Please follow the below instructions thoroughly in the same order mentioned.
-
We will be using the ZXing libraries for scanning the barcodes.
-
All the required files mentioned in the document are available in the zip file along with this document. Please refer the same.
Step-1: generating the Jar file which will be used for FFI integration. -
Download the latest ZXing project from the website - http://code.google.com/p/zxing/downloads/list. You may have a different version when you start downloading, so take the latest one. Right now, ZXing 2.1 is the latest one. So I will be using this.
-
Once we extract the ZXing zip file, we can see multiple folders inside it as shown below.
-
Create a folder ZXing_2.1 (you may use some other name also, the same name is not mandatory) in eclipse workspace and copy the “src” folder from /android. This src folder contains the google classes for barcode scanning.
-
Copy the Kony FFI class (Scanner.java) also into the src/com folder. So that we can see two folders inside src folder. They are google and kony as shown below.
-
Add R.java file at C:\workspace4.1\ZXing_2.1\src\com\google\zxing\client\android location. The downloaded ZXing will not have this file. Take this file from the zip.
-
Go to Java perspective in eclipse and create a Java project with name ZXing_2.1 and you will be able to see the project contents that we have copied.
-
Compile the core.jar available from ZXing with the JDK we have. All jars should be compiled with the same JDK. Below command will compile the core.jar with current JDK.
-
E:\Sheetz\barcode_scanning\zxing-2.1\core>ant -f build.xml
Buildfile: E:\Sheetz\barcode_scanning\zxing-2.1\core\build.xml
init:
build:
[mkdir] Created dir: E:\Sheetz\barcode_scanning\zxing-2.1\core\build
[javac] Compiling 190 source files to E:\Sheetz\barcode_scanning\zxing-2.1\core\build
[javac] Note: Some input files use unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
[jar] Building jar: E:\Sheetz\barcode_scanning\zxing-2.1\core\core.jar
BUILD SUCCESSFUL
Total time: 15 seconds
-
Add the external libraries from the build path as shown below. The jars need to be added are:
-
core.jar available from ZXing download (E:\Sheetz\barcode_scanning\zxing-2.1\core\core.jar)
-
android.jar from android sdk (E:\android-sdk-windows\platforms\android-11\android.jar)
-
konywidgets.jar from C:\workspace4.1\temp\scanbarcode\build\luaandroid\dist\scanbarcode\libs
-
Comment the below lines from the Java classes where you see errors, so that the errors will disappear.
-
import android.annotation.TargetApi;
-
@TargetApi()
-
Once all Java code is fine without errors, export the src folder as a jar file. You can use your own name. I am using ZXingBarcodeFFI.jar
-
Go to Kony perspective from eclipse and create a Kony project (scanbarcode).
-
Right click on project Properties Native App Android and add the below to the manifest
-
ACCESS_NETWORK_STATE e. CAMERA
-
ACCESS_COARSE_LOCATION f. READ_PHONE_STATE
-
GET_ACCOUNTS g. INTERNET
-
ACCESS_FINE_LOCATION h. ACCESS_NETWORK_STATE
The screen will look like this:
-
Similarly add the below content under “Child tag entries under tag:” section of Tags tab.
-
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">
|
-
Do the FFI integration as mentioned below.
-
Right click on project Integrate Third Party Manage Custom Libraries…
-
Add a LUA namespace as qrandroid
-
Right click on the namespace and add a lua method scanbarcode
-
Add a method parameter by clicking the + icon (add parameter) Name: callback and Data type: Closure
-
Expand the lua method and expand Mobile and select Android
-
Add the library created in step-1 (ZXingBarcodeFFI.jar) using click on Manage Library icon
-
Enter the package name as: com.kony.zxing.ffi
-
Enter class name as: Scanner
-
Do not select static checkbox
-
Enter the method name as: scanBarcode
-
Select the “Pass Activity Context Object to method as first parameter” option
-
Select return type as: void
-
The final FFI screen will look like this:
-
Click on Finish then you will be prompted with a message “Do you want to proceed with code generation for FFI Function?”. Click on Yes button.
-
You can see the ZXingBarcodeFFI.jar file at C:\workspace4.1\scanbarcode\resources\customlibs\lib\android folder.
-
Build the Kony project (Clean and Build for android)
-
Copy all files and folders from ~\barcode_scanning\zxing-2.1\android\assets to C:\workspace4.1\temp\scanbarcode\build\luaandroid\dist\scanbarcode\assets
-
Copy all files and folders from ~\barcode_scanning\zxing-2.1\android\res to C:\workspace4.1\temp\scanbarcode\build\luaandroid\dist\scanbarcode\res and remove drawable-xxhdpi folder
-
Edit AndroidManifest.XML (located at C:\workspace4.1\temp\\build\luaandroid\dist\) if any changes are required. For Example the App version needs to be targeted here while publishing the application. If there are no changes, no need to edit this file.
-
Go to C:\workspace4.1\temp\\build\luaandroid\dist\ folder and run ant debug command
C:\workspace4.1\temp\scanbarcode\build\luaandroid\dist\scanbarcode>ant debug
Buildfile: C:\workspace4.1\temp\scanbarcode\build\luaandroid\dist\scanbarcode\build.xml
-set-mode-check:
-set-debug-files:
-set-debug-mode:
-debug-obfuscation-check:
...
...
-do-debug:
[zipalign] Running zip align on final apk...
[echo] Debug Package: C:\workspace4.1\temp\scanbarcode\build\luaandroid\dist\scanbarcode\bin\scanbarcode-debug.apk
debug:
[propertyfile] Updating property file: C:\workspace4.1\temp\scanbarcode\build\lu
aandroid\dist\scanbarcode\bin\build.prop
[propertyfile] Updating property file: C:\workspace4.1\temp\scanbarcode\build\lu
aandroid\dist\scanbarcode\bin\build.prop
[propertyfile] Updating property file: C:\workspace4.1\temp\scanbarcode\build\lu
aandroid\dist\scanbarcode\bin\build.prop
[propertyfile] Updating property file: C:\workspace4.1\temp\scanbarcode\build\lu
aandroid\dist\scanbarcode\bin\build.prop
BUILD SUCCESSFUL
Total time: 16 seconds
-
Go to C:\workspace4.1\temp\scanbarcode\build\luaandroid\dist\\gen\com\\ folder and copy the R.java file to C:\workspace4.1\ZXing_2.1\src\com\google\zxing\client\android folder.
-
Edit the package name to com.google.zxing.client.android and generate the ZXingBarcodeFFI.jar file again.
-
Replace the ZXingBarcodeFFI.jar in C:\workspace4.1\temp\\build\luaandroid\dist\\libs with the newly created ZXingBarcodeFFI.jar file.
-
Also place the core.jar used in ZXing project.
-
Go to C:\workspace4.1\temp\\build\luaandroid\dist\ folder and run ant again.
-
Modified APK file will be available at C:\workspace4.1\temp\\build\luaandroid\dist\\bin folder.
-
Test the APK file on device. Not on emulator.
-
See the adb logcat for the result.
-
Write your application logic based on the captured values.
Step-4: Screens
-
Home page (having a button, upon clicking this button, the FFI function will be called).
-
Camera will be opened to scan the barcode or QR code
-
Value will be retrieved and displayed on a screen
Kony
Share with your friends: |