B4A Library CodeScanner - 100% embedded in B4A

A wrap for this Github Project. You need to download ZxingLatest.jar from the link below and then copy it to your additional libs folder:

https://drive.google.com/open?id=1h-qt0_fpgMF2gzBwZvoT1kmKLYuU7Fua

Posting the following:
1. B4A sample project
2. B4A library files - extract the jar and xml and copy them to your additional libs folder
3. The Java source code - enjoy!
4. LibRes.zip - extract it and then copy the LibRes folder and its contents to be on the same folder level as that of the /Files and /Objects folders of the B4A project

I have tested this on an Android 7.0 device only. Minimum SDK supported should be 14.

It allows for single and Continuous scanning
You can set the barcode "type" to be scanned (ALL, 1D, 2D)
See the below sample code for other options that can be set for the View or for the Scanner.

Sample Code:
B4X:
#Region  Project Attributes
    #ApplicationLabel: b4aCodeScanner
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: portrait
    #CanInstallToExternalStorage: False
#End Region

#AdditionalRes: ..\LibRes

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private cs1 As CodeScanner
    Private csv1 As CodeScannerView
    
    Private Button1 As Button
    Private Button2 As Button
    
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("main")
    
    csv1.AutoFocusButtonColor = Colors.Red
    csv1.AutoFocusButtonVisible = True
    csv1.AutoFocusEnabled = True
    csv1.FlashButtonColor = Colors.Green
    csv1.FlashButtonVisible = True
    csv1.FlashEnabled = True
    csv1.FrameColor = Colors.Blue
    csv1.FrameCornersSize = 200
    csv1.FrameThickness = 15
    csv1.MaskColor = Colors.ARGB(100, 200, 0, 0)
    
    
    cs1.Initialize("codescan", csv1)           'initialize CodeScanner with the CodeScannerView
    cs1.autoFocus = True                       'set autofocus to be true/false
    cs1.autoFocusInterval = 1500               'set the autofocus interval (milliseconds)
    cs1.autoFocusMode = cs1.FOCUS_MODE_SAFE    'or cs1.FOCUS_MODE_CONTINUOUS
    cs1.CameraToUse = cs1.CAMERA_BACK          'or cs1.CAMERA_FRONT
    cs1.flash = False                          'start or don't start the flash when the scanner starts
    cs1.formats = cs1.FORMATS_ALL              'or cs1.FORMATS_1D or cs1.FORMATS_2D
    cs1.ScanMode = cs1.SCAN_MODE_CONTINUOUS    'or cs1.SCAN_MODE_SINGLE
    'THIS MUST BE THE LAST CALL ONCE ALL OF THE ABOVE HAVE BEEN SET
    cs1.build

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)
    
    cs1.stopScan

End Sub


Sub Button1_Click
    
    cs1.startScan
    
End Sub

Sub Button2_Click
    
    cs1.stopScan
    
End Sub

Sub codescan_scan_result(rst As String)
    
    Log("B4A Result = " & rst)
    
End Sub

1.png



2.png
 

Attachments

  • b4aLibFiles.zip
    47 KB · Views: 582
  • LibRes.zip
    11 KB · Views: 575
  • TheJavaCode.zip
    32.6 KB · Views: 584
  • b4aCodeScanner.zip
    8.6 KB · Views: 584

OMS

Member
Hello,

I know this is an old thread but I really hope Mr. Johan Schoeman reads this and reply.
I am using another barcode scanner (ZXingLib by icefairy333 - modified by Johan) which is really perfect.
But now I need this library (CodeScanner - 100% embedded in B4A), Why? because this one does not go to another activity.
The problem of this one, is that pre-view panel size is not customizable (I want to a have narrow bar for scan-panel on top of activity and use the rest space for other veiws and a list e.g ) . Also Zoom size of camera is not the same as icefairy333 ( I think , it is zooming out, somehow)
I am not able to modify java code. so, I ask you please make it more power full as I said.
Another option is having a library that just gets bmp and retrieve barcodes, this lets me use camera library and do anything I need by myself.

Thank you
 
Last edited:

OMS

Member
hello again,
I tried to compile the java code of this library with Simple Library Compiler But it stops with following Error:

D:\Programing\Android\Projects\SimpleLibraryCompiler\CodeScanner\src\com\budiyev\android\codescanner\CodeScannerView.java:30: error: package android.support.annotation does not exist
import android.support.annotation.AttrRes;
___________________^
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
1 error

I am sure there are needed files on my additional Libs folder:
support-annotations.jar
support-annotations-28.0.0.jar
android-support-annotations.jar
 

Johan Schoeman

Expert
Licensed User
Longtime User
hello again,
I tried to compile the java code of this library with Simple Library Compiler But it stops with following Error:

D:\Programing\Android\Projects\SimpleLibraryCompiler\CodeScanner\src\com\budiyev\android\codescanner\CodeScannerView.java:30: error: package android.support.annotation does not exist
import android.support.annotation.AttrRes;
___________________^
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
1 error

I am sure there are needed files on my additional Libs folder:
support-annotations.jar
support-annotations-28.0.0.jar
android-support-annotations.jar
Do you have the annotation jars inside the Libs folder of the Java project? Eg folder level

src
Libs
...... Jar1
........Jar2

Jars must be in the Libs folder
 

OMS

Member
Thank you.
I did not know that there must be a Libs folder for compiling projects with SLC. (I used to think SLC takes jars from B4A additional libs !!)
 

OMS

Member
Hello again
I have an old device that behaves differently with this library : Light exposure is a bit more than needed.
I tested with another libs (ZXingLib by icefairy333 - modified by Johan Schoeman and some others) but image preview was better (darker).
Is it possible to correct this problem with library?
 
Top