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

Johan Schoeman

Expert
Licensed User
Longtime User
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
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
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
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…