Liner Barcode and qr code reader application for android platforms



Download 25.7 Kb.
Date14.06.2017
Size25.7 Kb.
#20865



Liner Barcode and QR code reader application for android platforms



  • 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.


  1. 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.



  1. Once we extract the ZXing zip file, we can see multiple folders inside it as shown below.



  1. 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.

  2. 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.



  1. 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.

  2. 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.



  1. 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.

    1. 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



  1. Add the external libraries from the build path as shown below. The jars need to be added are:

    1. core.jar available from ZXing download (E:\Sheetz\barcode_scanning\zxing-2.1\core\core.jar)

    2. android.jar from android sdk (E:\android-sdk-windows\platforms\android-11\android.jar)

    3. konywidgets.jar from C:\workspace4.1\temp\scanbarcode\build\luaandroid\dist\scanbarcode\libs



  1. Comment the below lines from the Java classes where you see errors, so that the errors will disappear.

    1. import android.annotation.TargetApi;

    2. @TargetApi()

  2. 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

Step-2: Creating a Kony project and integrating with FFI


  1. Go to Kony perspective from eclipse and create a Kony project (scanbarcode).

  2. Right click on project  Properties  Native App  Android and add the below to the manifest

    1. ACCESS_NETWORK_STATE e. CAMERA

    2. ACCESS_COARSE_LOCATION f. READ_PHONE_STATE

    3. GET_ACCOUNTS g. INTERNET

    4. ACCESS_FINE_LOCATION h. ACCESS_NETWORK_STATE

The screen will look like this:



  1. 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">























  1. Do the FFI integration as mentioned below.

    1. Right click on project  Integrate Third Party  Manage Custom Libraries…

    2. Add a LUA namespace as qrandroid

    3. Right click on the namespace and add a lua method scanbarcode

    4. Add a method parameter by clicking the + icon (add parameter)  Name: callback and Data type: Closure

    5. Expand the lua method and expand Mobile and select Android

    6. Add the library created in step-1 (ZXingBarcodeFFI.jar) using click on Manage Library icon

    7. Enter the package name as: com.kony.zxing.ffi

    8. Enter class name as: Scanner

    9. Do not select static checkbox

    10. Enter the method name as: scanBarcode

    11. Select the “Pass Activity Context Object to method as first parameter” option

    12. Select return type as: void

    13. The final FFI screen will look like this:



    1. 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.

    2. You can see the ZXingBarcodeFFI.jar file at C:\workspace4.1\scanbarcode\resources\customlibs\lib\android folder.

Step-3: Bundling the reader with Kony Application


  1. Build the Kony project (Clean and Build for android)

  2. Copy all files and folders from ~\barcode_scanning\zxing-2.1\android\assets to C:\workspace4.1\temp\scanbarcode\build\luaandroid\dist\scanbarcode\assets

  3. 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

  4. 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.

  5. 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



  1. 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.

  2. Edit the package name to com.google.zxing.client.android and generate the ZXingBarcodeFFI.jar file again.

  3. Replace the ZXingBarcodeFFI.jar in C:\workspace4.1\temp\\build\luaandroid\dist\\libs with the newly created ZXingBarcodeFFI.jar file.

  4. Also place the core.jar used in ZXing project.

  5. Go to C:\workspace4.1\temp\\build\luaandroid\dist\ folder and run ant again.

  6. Modified APK file will be available at C:\workspace4.1\temp\\build\luaandroid\dist\\bin folder.

  7. Test the APK file on device. Not on emulator.

  8. See the adb logcat for the result.

  9. Write your application logic based on the captured values.

Step-4: Screens

  1. Home page (having a button, upon clicking this button, the FFI function will be called).



  1. Camera will be opened to scan the barcode or QR code



  1. Value will be retrieved and displayed on a screen



Kony








Download 25.7 Kb.

Share with your friends:




The database is protected by copyright ©ininet.org 2024
send message

    Main page