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: 510
  • LibRes.zip
    11 KB · Views: 484
  • TheJavaCode.zip
    32.6 KB · Views: 496
  • b4aCodeScanner.zip
    8.6 KB · Views: 500
Top