B4A Library Android Vision Barcode Scanner (Scan QR Codes and other 1D & 2D barcodes)

It seems to be BARCODE season....This is a (partial) wrap for this Github project. It also uses the Google Mobile Vision API to scan the codes. It also incorporates the Tracking functionality (I have not quite figured out what color "outlined" barcode is actually the one that will be returned to B4A when it is tapped/touched).

Posting the following:
1. B4A project - best to use it in the two activities as per the attached B4A sample project. (b4aAndroidVisionMaster.zip
2. The B4A library files (b4aAndroidVisionMasterLibFiles.zip)
3. The java code as it stands at present (TheJavaCode.zip)
4. A link to all the other jars that will be required - download them from here and copy them to your additional library folder - https://www.dropbox.com/s/se5x5znl1tgpv6r/OtherLibFiles.zip?dl=0
5. resourceInAddLibFolder.zip - extract it and copy the resource folder to your additional library folder
6. resource.zip - extract it and copy the resource folder to the same folder level that of the /Files and /Objects folders of the B4A project.

Touch/tap a highlighted barcode when the scanner is active to return the barcode format and content/value to the B4A project.

Please note: This is by no means perfect and I therefore leave you with the Java Code to change it to whatever might suite you - but it is working as it is at present.

You can also try the Google Mobile Vision Face Detector that I have posted HERE

You can download and test any posting of mine in this thread but if you want to use it then you need to

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

#AdditionalRes: ..\resource

#AdditionalRes: C:\Users\----------2\Documents\Basic 4 Android\JOHAN APPS\JHS LIBS\resource\b4a_appcompat, de.amberhome.objects.appcompat
#AdditionalRes: C:\ANDRIOD_SDK_TOOLS\extras\android\support\v7\appcompat\res, android.support.v7.appcompat
#AdditionalRes: C:\ANDRIOD_SDK_TOOLS\extras\google\google_play_services\libproject\google-play-services_lib\res, com.google.android.gms
#AdditionalRes: C:\ANDRIOD_SDK_TOOLS\extras\android\support\design\res, android.support.design

#ExcludeClasses: .games, .drive, .ads, .fitness, .wearable, .measurement, .cast, .auth, .nearby
#ExcludeClasses: .tagmanager, .analytics, .wallet, .plus, .gcm, .maps, .panorama

#Extends: android.support.v7.app.AppCompatActivity


#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 Button1 As Button

    Private Label1 As Label
    Private Label2 As Label
    Private Label4 As Label
    Private Label3 As Label
    Dim settings(2) As Boolean

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")
    Label1.Text = ""
    Label2.Text = ""
    Label3.Text = "Flash Disabled"
    Label4.Text = "Auto Focus Enabled"
    settings(0) = False
    settings(1) = True

End Sub

Sub Activity_Resume



End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub Button1_Click

  CallSubDelayed2(Main_Scanner, "StartScan", settings)

End Sub

Sub GetResult(retval() As String)

    Log("back in main : format = " & retval(0))
    Log("back in main : data = " & retval(1))

    Label1.Text = "Barcode Format : " & retval(0)
    Label2.Text = "Barcode Data : " & retval(1)

End Sub

Sub Label3_Click

    If Label3.Text = "Flash Disabled" Then
      Label3.Text = "Flash Enabled"
      Label3.Color = Colors.Red
      settings(0) = True
    Else
        Label3.Color = 0xff008000
        Label3.Text = "Flash Disabled"
        settings(0) = False
    End If

End Sub

Sub Label4_Click

    If Label4.Text = "Auto Focus Disabled" Then
      Label4.Text = "Auto Focus Enabled"
      Label4.Color = Colors.Red
      settings(1) = True
    Else
        Label4.Color = 0xff008000
        Label4.Text = "Auto Focus Disabled"
        settings(1) = False
    End If


End Sub

Sample code (Main_Scanner Activity):
B4X:
#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.

        Dim myscan As AndroidVisionMaster

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("main2")
    myscan.Initialize("scanner")




End Sub

Sub Activity_Resume



End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub StartScan(settings() As Boolean)

    If settings(0) = True Then myscan.FlashOn = True
    If settings(0) = False Then myscan.FlashOn = False

    If settings(1) = True Then myscan.AutoFocus = True
    If settings(1) = False Then myscan.AutoFocus = False

    myscan.beginScan



End Sub

Sub ToggleFlash_Click


End Sub

Sub scanner_scan_result(data As String, format As Int)


    Dim fmt As String = ""
    Select format
        Case 0
            fmt = "ALL_FORMATS"
        Case 1
            fmt = "CODE_128"
        Case 2
            fmt = " CODE_39"
        Case 4
            fmt = "CODE_93"
        Case 8
            fmt = "CODABAR"
        Case 16
            fmt = "DATA_MATRIX"
        Case 32
            fmt = "EAN_13"
        Case 64
            fmt = "EAN_8"
        Case 128
            fmt = "ITF"
        Case 256
            fmt = "QR_CODE"
        Case 512
            fmt = "UPC_A"
        Case 1024
            fmt = "UPC_E"
        Case 2048
            fmt = "= PDF417"
        Case 4096
            fmt = "AZTEC"
          
    End Select

    Dim retval(2) As String
    retval(0) = fmt
    retval(1) = data

    CallSubDelayed2(Main, "GetResult", retval)

    Log("Format : " & fmt)
    Log("Data : " & data)

    Activity.Finish

End Sub

Important: Take note of all the files in the B4A project's /Objects/res/blabla folders. Make sure they are set to READ ONLY before you compile the project for the first time

Also important to note the B4A project's Manifest Files

And equally important to set your paths correctly (the below only applicable to my folder setup):
B4X:
#End Region

#AdditionalRes: ..\resource

#AdditionalRes: C:\Users\----------2\Documents\Basic 4 Android\JOHAN APPS\JHS LIBS\resource\b4a_appcompat, de.amberhome.objects.appcompat
#AdditionalRes: C:\ANDRIOD_SDK_TOOLS\extras\android\support\v7\appcompat\res, android.support.v7.appcompat
#AdditionalRes: C:\ANDRIOD_SDK_TOOLS\extras\google\google_play_services\libproject\google-play-services_lib\res, com.google.android.gms
#AdditionalRes: C:\ANDRIOD_SDK_TOOLS\extras\android\support\design\res, android.support.design

#ExcludeClasses: .games, .drive, .ads, .fitness, .wearable, .measurement, .cast, .auth, .nearby
#ExcludeClasses: .tagmanager, .analytics, .wallet, .plus, .gcm, .maps, .panorama

#Extends: android.support.v7.app.AppCompatActivity

#Region  Activity Attributes

Library as it stands at present:

AndroidVisionMaster
Author:
Github: Clayton Wilkinson, Wrapped by: Johan Schoeman
Version: 1
  • AndroidVisionMaster
    Events:
    • scan_result (data As String, format As Int)
    Methods:
    • BeginScan
    • Initialize (paramString As String)
    • IsInitialized As Boolean
    • onClick (v As View)
      Called when a view has been clicked.
      v: The view that was clicked.
    Permissions:
    • android.hardware.camera
    • android.hardware.camera.autofocus
    • android.permission.CAMERA
    • android.permission.FLASHLIGHT
    • android.permission.VIBRATE
    • android.permission.WRITE_EXTERNAL_STORAGE
    Properties:
    • AutoFocus As Boolean [write only]
    • FlashOn As Boolean [write only]




B4A PROJECT STARTED
start.png


ENABLE THE FLASH LIGHT WHEN THE SCANNER BECOMES ACTIVE
Flash Enabled.png



FLASH AND AUTO FOCUS ENABLED WHEN THE SCANNER BECOMES ACTIVE
flash and autofocus enabled.png



SCANNER STARTED AND MULTI TRACKING OCCURRING
multitracking.png



AFTER A HIGHLIGHTED BARCODE HAS BEEN TOUCHED/TAPPED
hightlighted barcode tapped touched.png


Will help with the B4A setup but any further changes to the library will be up to you....
 

Attachments

  • b4aAndroidVisionMaster.zip
    34.5 KB · Views: 879
  • b4aAndroidVisionMasterLibFiles.zip
    40.4 KB · Views: 841
  • resourceInAddLibFolder.zip
    775 bytes · Views: 862
  • resource.zip
    423 bytes · Views: 836
  • TheJavaCode.zip
    61.8 KB · Views: 666
Last edited:

Johan Schoeman

Expert
Licensed User
Hello Johan,
did you have the time to look at the matter again?
I would be really grateful if you could find a solution.
Thank you!

:( Micholl
Michael, I have run into the same problem with a different project the other day and got it to work on an Android 7 device by changing the max SDK in the manifest. The bad news is that I reversed all the changes that I made so will have to revisit it and implement the required changes again. Will see if I can get to it sometime this coming weekend.
 
Top