B4A Library KingsMentor/MobileVisionBarcodeScanner

A shortcut wrap for this Github project

1. Extract resource.zip and copy the folder and its contents to be on the same folder level as that of the /Files and /Objects folders of the attached B4A project.
2. Extract LibRes.zip and copy the folder and its contents to be on the same folder level as that of the /Files and /Objects folders of the attached B4A project.
3. Extract DemoRes.zip and copy the folder and its contents to be on the same folder level as that of the /Files and /Objects folders of the attached B4A project.
4. Copy the b4a lib files to your additional libs folder (jar and xml)

Touch on a highlighted barcode - the touched barcode value and value of other highlighted barcodes at the time of touch will be returned to the B4A project via an event in the B4A project.

Tested on B4A V8.30, targetSDK = 26, Android 8.0.0 (Samsung Experience Version 9.0)

Let me know if you get stuck. Will help to sort it out. But there should not be anything extraordinary to this project. Should be simple if you have your SDK updated and your paths set correctly.

Edit: Also tested with B4A v8.50 BETA and working ;)


1.png



2.png



Library:
KingsMentor
Author:
Github: KingsMentor, Wrapped by: Johan Schoeman
Version: 1.02
  • KingsMentor
    Events:
    • scan_result (data As Object, closeby As String)
    Methods:
    • BeginScan As void
    • IsInitialized As boolean
    • Initialize (paramBA As anywheresoftware.b4a.BA, paramString As java.lang.String) As void
    Properties:
    • BarcodeTextSize As float [write only]
    • BarcodeRectangleStrokeWidth As float [write only]


Sample Code:

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

#AdditionalRes: ..\DemoRes
#AdditionalRes: ..\LibRes
#AdditionalRes: ..\resource


#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.
 
    Dim rp As RuntimePermissions

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
 
    Dim km As KingsMentor
    Private Label1 As Label
    Private Label2 As Label
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")
    km.Initialize("junk")
 
    km.BarcodeTextSize = 40.0
    km.BarcodeRectangleStrokeWidth = 15.0
 
    Label1.Visible = False
    Label2.Visible = False

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub Button1_Click

    Label1.Visible = False
    Label2.Visible = False
    Dim Result As Boolean = True
    If Not(rp.Check(rp.PERMISSION_CAMERA)) Then
        rp.CheckAndRequest(rp.PERMISSION_CAMERA)
        Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
    End If
    If Result Then
      km.BeginScan
    End If
 
End Sub

Sub junk_scan_result(data As Object, closeby As String)
 
'   Log(" ")
'   Log("closest code touched = " & closeby)
'   Log(" ")
 
   Label1.Visible = True
   Label1.Text = "Barcode clicked : " & closeby
 
   Label2.Visible = True
   Label2.Text = "Barcodes highlighted when touched:"

   Dim finalstring As String = ""
   Dim mylist As List = data
   For i = 0 To mylist.Size - 1 Step 3
'        Log("barcode value : " & mylist.Get(i))
'     Log("barcode type  : " & mylist.Get(i+1))
'     Log("barcode data  : " & mylist.Get(i+2))
'     Log(" ")
        finalstring = finalstring & mylist.Get(i+2) & Chr(10)
   Next
 
   Label2.Text = Label2.Text & Chr(10) & Chr(10) & finalstring
 
End Sub
 

Attachments

  • LibRes.zip
    2 KB · Views: 335
  • resource.zip
    423 bytes · Views: 337
  • b4aKingsMentor.zip
    8.9 KB · Views: 302
  • DemoRes.zip
    57.7 KB · Views: 298
  • b4aKingsMentorLibFiles.zip
    51.6 KB · Views: 320
Last edited:

Johan Schoeman

Expert
Licensed User
Longtime User
Earlier today I have updated my B4A from v9.00 to v9.30 and then from v9.30 to v9.50
I tested my project in post #1 but got an error. Browsing around in the B4X forum I found the solution - the layout file (activity_main.xml) in folder DemoRes required some changes in some places from

B4X:
android.support.v7.widget.SwitchCompat

to

B4X:
androidx.appcompat.widget.SwitchCompat

The library will be "jetified" if you select Tools->Jetifier (AndroidX) as the wrapper uses:

B4X:
@DependsOn(values={"com.android.support:support-v4", "com.android.support:appcompat-v7", "com.google.android.gms:play-services-vision", "com.android.support:design"})

Attached is the updated DemoRes folder (zipped). Once extracted, replace the original DemoRes folder (i.e the one in post #1) with the attached folder.

Tested and working on Android 9 (Galaxy S10) with B4A v9.50 after SDK update and running the Jetifier.

Enjoy!
 

Attachments

  • DemoRes_b4a9.30.zip
    57.7 KB · Views: 238
Last edited:
Hello Johan,

Good project, It seems very fast to read qrcode. I´ve testing and apparently the "scan_result" is not triggering.

I checked the java code but apparently everything is correct there, the line events to result is declared:

B4X:
@Events(values={"scan_result(data As Object, closeby As String)"})

I tried to compile the Java but I got the errors:

\BarcodeCapture.java:28: error: package android.support.annotation does not exist import android.support.annotation.NonNull;
\BarcodeCapture.java:29: error: package android.support.annotation does not exist import android.support.annotation.Nullable
\BarcodeCapture.java:40: error: package com.google.android.gms.common does not exist import com.google.android.gms.common.ConnectionResult;

My knowledge in java is limited, could you help me to check this code?

tks,

Leandro
 
Last edited:
Top