B4A Library QRCodeReaderView - QR Code Scanner that is also 100% embedded in B4A (new B4A lib files in post #8)

Here is another scanner that is 100% embedded in B4A. It wraps this Github project and will only scan QR Codes (it uses the ZXING engine for decoding scanned QR Codes). It will keep on reading QR codes for as long as what it finds a valid QR code. It is quite a "speedy" scanner. It does not require any other barcode scanner app to be installed on your device - it is 100% standalone. You can customize your B4A activity / UI by adding buttons, labels, panels, images, etc etc and change colors to your liking - 100% B4A customizable.

Note that a panel is the parent of the custom view but seeing that the original project extends Surface View it will punch a hole in the panel when the scanner starts.

Also note the permissions in the B4A project's manifest file (I know majority are redundant for this project).

You will have to handle consecutive / continuous scans of the same QR code within your B4A code.

Posting the following:
1. B4A project
2. B4A library files (3 x jar and 1 x xml) - copy them to your additional library folder.

EDIT: UPDATED LIBRARY FILES IN POST #6 THAT WILL NOT RAISE AN EVENT IN B4A IF TWO CONSECUTIVE SCANS OF THE SAME QR CODE OCCURS

1.png



Scanner.png



2.png


Some sample code:

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

#End Region

#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 qrcrv As QRCodeReaderView

    Private b1 As Button
    Private b2 As Button
    Private p1 As Panel
    Private l1 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")

    qrcrv.Visible = False


End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub b1_Click


    qrcrv.Visible = True
    DoEvents
    qrcrv.startScan

End Sub
Sub b2_Click

    qrcrv.stopScan
    DoEvents
    qrcrv.Visible = False

End Sub

Sub qrcrv_result_found(retval As String)

    Log("B4A: " & retval)
    l1.Text = retval

End Sub


The library:

QRCodeReaderView
Author:
Github: David L\u00e1zaro, Wrapped by: Johan Schoeman
Version: 1
QRCodeReaderView
Events:

  • result_found (retval As String)
Fields:
  • ba As BA
Methods:
  • BringToFront
  • DesignerCreateView (base As PanelWrapper, lw As LabelWrapper, props As Map)
  • Initialize (EventName As String)
  • Invalidate
  • Invalidate2 (arg0 As Rect)
  • Invalidate3 (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
  • IsInitialized As Boolean
  • RemoveView
  • RequestFocus As Boolean
  • SendToBack
  • SetBackgroundImage (arg0 As Bitmap)
  • SetColorAnimated (arg0 As Int, arg1 As Int, arg2 As Int)
  • SetLayout (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
  • SetLayoutAnimated (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int, arg4 As Int)
  • SetVisibleAnimated (arg0 As Int, arg1 As Boolean)
  • startScan
  • stopScan
Properties:
  • Background As Drawable
  • Color As Int [write only]
  • Enabled As Boolean
  • Height As Int
  • Left As Int
  • Tag As Object
  • Top As Int
  • Visible As Boolean
  • Width As Int
You can download and test any posting of mine in this thread but if you want to use it then you need to
 

Attachments

  • QRCodeReaderViewLibFiles.zip
    498.1 KB · Views: 3,257
  • b4aQRCodeReaderView.zip
    8.9 KB · Views: 2,831
Last edited:

Johan Schoeman

Expert
Licensed User
Longtime User
Hello. I'm new to B4X and only needed it for a small QR-project at work, so this is my first time using it. This library works great and is really easy to use, but was just wondering if it's possible to change the camera to not use wide angle somehow? It still works but looks a bit funky :)

Thank you.
You can try this

See the mod to the code in post #8 of that thread to use RuntimePermissions. If it does not work for you - there are multiple barcode scanners projects posted in the forum that you can try. I only use one - zxing by @icefairy that a have modified sometime in 2015 (if memory serves me correctly).

 
Last edited:

Dwnr80

New Member
See the mod to the code in post #8 of that thread to use RuntimePermissions. If it does not work for you - there are multiple barcode scanners projects posted in the forum that you can try. I only use one - zxing by @icefairy that a have modified sometime in 2015 (if memory serves me correctly).
I had to try a whole bunch 'til there was one that didn't use my phones wide angle. Think you made that one as well, so thank you!
 

Emid

Member
Here is another scanner that is 100% embedded in B4A. It wraps this Github project and will only scan QR Codes (it uses the ZXING engine for decoding scanned QR Codes). It will keep on reading QR codes for as long as what it finds a valid QR code. It is quite a "speedy" scanner. It does not require any other barcode scanner app to be installed on your device - it is 100% standalone. You can customize your B4A activity / UI by adding buttons, labels, panels, images, etc etc and change colors to your liking - 100% B4A customizable.

Note that a panel is the parent of the custom view but seeing that the original project extends Surface View it will punch a hole in the panel when the scanner starts.

Also note the permissions in the B4A project's manifest file (I know majority are redundant for this project).

You will have to handle consecutive / continuous scans of the same QR code within your B4A code.

Posting the following:
1. B4A project
2. B4A library files (3 x jar and 1 x xml) - copy them to your additional library folder.

EDIT: UPDATED LIBRARY FILES IN POST #6 THAT WILL NOT RAISE AN EVENT IN B4A IF TWO CONSECUTIVE SCANS OF THE SAME QR CODE OCCURS

View attachment 39086


View attachment 39240


View attachment 39087

Some sample code:

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

#End Region

#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 qrcrv As QRCodeReaderView

    Private b1 As Button
    Private b2 As Button
    Private p1 As Panel
    Private l1 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")

    qrcrv.Visible = False


End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub b1_Click


    qrcrv.Visible = True
    DoEvents
    qrcrv.startScan

End Sub
Sub b2_Click

    qrcrv.stopScan
    DoEvents
    qrcrv.Visible = False

End Sub

Sub qrcrv_result_found(retval As String)

    Log("B4A: " & retval)
    l1.Text = retval

End Sub


The library:

QRCodeReaderView
Author:
Github: David L\u00e1zaro, Wrapped by: Johan Schoeman
Version: 1
QRCodeReaderView
Events:

  • result_found (retval As String)
Fields:
  • ba As BA
Methods:
  • BringToFront
  • DesignerCreateView (base As PanelWrapper, lw As LabelWrapper, props As Map)
  • Initialize (EventName As String)
  • Invalidate
  • Invalidate2 (arg0 As Rect)
  • Invalidate3 (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
  • IsInitialized As Boolean
  • RemoveView
  • RequestFocus As Boolean
  • SendToBack
  • SetBackgroundImage (arg0 As Bitmap)
  • SetColorAnimated (arg0 As Int, arg1 As Int, arg2 As Int)
  • SetLayout (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
  • SetLayoutAnimated (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int, arg4 As Int)
  • SetVisibleAnimated (arg0 As Int, arg1 As Boolean)
  • startScan
  • stopScan
Properties:
  • Background As Drawable
  • Color As Int [write only]
  • Enabled As Boolean
  • Height As Int
  • Left As Int
  • Tag As Object
  • Top As Int
  • Visible As Boolean
  • Width As Int
You can download and test any posting of mine in this thread but if you want to use it then you need to
Great...
I am using android box and I am using webcam as a camera,
How can I add USB camera to your code?
so, it cannot decode Azteq barcode.
Can I run in background?
Regards.
 

b4x-de

Active Member
Licensed User
Longtime User
For me it works on SDK 33. What error message your receive on your device? Give us some details please to help you.
 
i test QR reader in PlayStore on old tablet.
it can scan fast and easy.

but in this library cannot read same QRcode as good as other software.
i must change distanse more and more time amd change light degree then naybe read . but other software in first scan can read .

via my phone sumsong a31 it work ok but on sumsong tab10 not good
 
it is my code:
my code QR:
#Region Shared Files
#CustomBuildAction: folders ready, %WINDIR%\System32\Robocopy.exe,"..\..\Shared Files" "..\Files"
'Ctrl + click to sync files: ide://run?file=%WINDIR%\System32\Robocopy.exe&args=..\..\Shared+Files&args=..\Files&FilesSync=True
#End Region

'Ctrl + click to export as zip: ide://run?File=%B4X%\Zipper.jar&Args=Project.zip

Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private Button1 As Button
    Private Button2 As Button
    Private Button3 As Button
      
    Private btnStopQR As Button
    Private btnStartQR As Button
    Private EditText1 As EditText
    
    Private qrcrv As QRCodeReaderView
    Dim currentCameraId As String = "CAMERA_BACK"
    Private oldString As String = ""
End Sub

Public Sub Initialize
'    B4XPages.GetManager.LogEvents = True
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    qrcrv.Visible = False

    'Keep the order of the next 4 lines. CAMERA_BACK and CAMERA_FRONT will only contain correct values once qrcrv.BackFacingCamera and qrcrv.FrontFacingCamera has
    'been executed else they will have default values of -1
    Log(qrcrv.BackFacingCamera)    'see the popup help when entering this method - check if there is a back facing camera and return the ID of the camera
    Log(qrcrv.FrontFacingCamera)   'see the popup help when entering this method - check if there is a front facing camera and retutn the ID of the camera
    
    Log(qrcrv.CAMERA_BACK)         'see the popup help when entering this method
    Log(qrcrv.CAMERA_FRONT)           'see the popup help when entering this method
    
    Button1_Click'qrcrv.CameraId = qrcrv.CAMERA_BACK
    btnStartQR_Click
End Sub

'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.


Private Sub btnStartQR_Click
    If qrcrv.Visible = False Then
        qrcrv.Visible = True
        DoEvents
        qrcrv.startScan
        btnStartQR.Text="Stop"
    Else
        qrcrv.stopScan
        DoEvents
        qrcrv.Visible = False
        btnStartQR.Text="Start"
    End If
End Sub
        

Private Sub btnStopQR_Click
    If (qrcrv.isFlashOn = True) Then
        qrcrv.setFlashOff
    Else
        qrcrv.setFlashOn
    End If   

End Sub


Sub qrcrv_result_found(retval As String)
    
    If oldString <> retval Then
      oldString = retval
      Log("B4A: " & oldString)
      EditText1.Text = oldString
      
    If retval.Contains("KP4") Then
        btnStopQR_Click
    End If
    End If
    
End Sub

Sub calc_ean_checksum(number As String) As String
    Dim i As Int
    Dim c As Char
    Dim soma As Int
    Dim n As Int
    Dim digit As Float
  
    soma = 0
    For i=0 To number.Length - 1
        digit = number.SubString2(i,i+1)
        n= digit * ((i Mod 2) * 2 + 1)
        soma=soma+n
    Next
    Return number & ( ( 10 - ( soma Mod 10 )) Mod 10 )
End Sub

 

Private Sub Button1_Click
    If currentCameraId = "CAMERA_BACK" Then
        qrcrv.CameraId = qrcrv.CAMERA_FRONT   'or qrcrv.CameraId = qrcrv.CAMERA_BACK
        currentCameraId = "CAMERA_FFONT"
        Button1.Text = "FRN"
    Else
        qrcrv.CameraId = qrcrv.CAMERA_BACK   'or qrcrv.CameraId = qrcrv.CAMERA_BACK
        currentCameraId = "CAMERA_BACK"
        Button1.Text = "TOP"
    End If
    
    qrcrv.stopScan
    DoEvents
    qrcrv.Visible = False
    
    qrcrv.Visible = True
    DoEvents
    qrcrv.startScan
    'xui.MsgboxAsync("Hello world!", "B4X")
    
End Sub


Sub Button2_Click
  
    
  
End Sub


Sub Button3_Click
  
    
  
End Sub


Sub Button4_Click
  
    
  
End Sub

manifest:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="29"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
'End of default text.
              
AddPermission("android.permission.BIND_DREAM_SERVICE")
 

AddManifestText(<uses-feature android:name="android.hardware.telephony" android:required="false" />)
AddManifestText(<uses-feature android:name="android.hardware.camera" android:required="false" />)
AddManifestText(<uses-feature android:name="android.hardware.camera.autofocus" android:required="false" />)
AddManifestText(<uses-feature android:name="android.hardware.camera.flash" android:required="true" />)
'AddPermission("android.permission.ACCESS_COARSE_LOCATION")
AddPermission("android.permission.INTERNET")
AddPermission("android.permission.ACCESS_FINE_LOCATION")
AddPermission("android.permission.WAKE_LOCK")
AddPermission("android.permission.DEVICE_POWER")
'AddPermission("android.permission.ACCESS_COARSE_UPDATES")
AddPermission("android.permission.READ_PHONE_STATE")
AddPermission("android.permission.VIBRATE")
AddPermission("android.permission.CAMERA")
AddPermission("android.permission.FLASHLIGHT")
AddPermission("android.hardware.camera")

SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.LightTheme)
 

Johan Schoeman

Expert
Licensed User
Longtime User
؟ i have only this source code
where i must edit?
 
new link tested

more more error..

Dex merge Error
Error in D:\~Data\B4A\Android SDK\tools\..\extras\b4a_local\unpacked-qrcodereaderview-63593915924000\dex_v1\qrcodereaderview.zip:classes.dex:
Type com.dlazaro66.qrcodereaderview.QRCodeReaderView$Callback is defined multiple times: D:\~Data\B4A\Android SDK\tools\..\extras\b4a_local\unpacked-qrcodereaderview-63593915924000\dex_v1\qrcodereaderview.zip:classes.dex, D:\~Data\B4A\Android SDK\tools\..\extras\b4a_local\unpacked-qrcodereaderv102-63664056220000\dex_v1\qrcodereaderv102.zip:classes.dex
Compilation failed
.....
 
old message : i add old library and new lib in same time. sorry....

it work ok
in sdk 33 work true

but in this line crash app
nativeMe.RunMethod("playTone", Null)


what is this line action?
 
please same as this Library if is trusted by B4A company, Add in sample of new version of B4A .
this is good for developer and new users.
thanks a lot
 
Top