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:

junaidahmed

Well-Known Member
Licensed User
Longtime User
Please check below log error and advise how to solve this issue....

Logger connected to: samsung SM-G610F
--------- beginning of crash
--------- beginning of main
--------- beginning of system
Copying updated assets files (3)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
java.lang.RuntimeException: Fail to connect to camera service
at android.hardware.Camera.<init>(Camera.java:519)
at android.hardware.Camera.open(Camera.java:364)
at com.google.zxing.client.android.camera.open.OpenCameraInterface.open(OpenCameraInterface.java:76)
at com.google.zxing.client.android.camera.CameraManager.openDriver(CameraManager.java:104)
at com.dlazaro66.qrcodereaderview.QRCodeReaderView.surfaceCreated(QRCodeReaderView.java:232)
at android.view.SurfaceView.updateWindow(SurfaceView.java:656)
at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:172)
at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:1013)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2542)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1537)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7183)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:959)
at android.view.Choreographer.doCallbacks(Choreographer.java:734)
at android.view.Choreographer.doFrame(Choreographer.java:670)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:945)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6776)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1518)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)
 
Hello! I made a project with your library. I tried to do the same steps like in the example project but when I start scanning in my project the scanner seems to be not working. but with the same QR code in the example project it works. Perhaps I'm doing something wrong?

B4X:
#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: False
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    'These variables can be accessed from all modules.
    Private xui As XUI
    Dim access As Accessiblity 'Variable de la accesibilidad del usuario
    Private lytValores As LayoutValues
    
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 LectorQR As QRCodesReaderView
    Private btnEscanear As Button
'    Private lblResultado As Label
    Private QRCodeReaderView1 As QRCodeReaderView
    Private lblResultado As Label
    Private Label1 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("Lector")
    lytValores=GetDeviceLayoutValues
    Escalar(Activity)
    ResetUserFontScale(Activity)
'   
    QRCodeReaderView1.Visible = False

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub ResetUserFontScale(p As Panel)
    'Reconfigurar tamaño de fuente del dispositivo, impedir que se escale
    ' For Each v As View In activity.GetAllViewsRecursive
'    For Each v As View In p
    For Each v As View In p
        If v Is Panel Then
            ResetUserFontScale(v)
        Else If v Is Label Then
            Dim lbl As Label = v
            'De acuerdo a la escala de configuración del dispositivo determino los tamaños de texto:
            If lytValores.Scale <= 1 Then
                lbl.TextSize = lbl.TextSize / access.GetUserFontScale + 12
            Else If lytValores.Scale < 2 Then
                If lbl.TextSize<=14 Then
                    lbl.TextSize = lbl.TextSize / access.GetUserFontScale + 3.5
                Else
                    lbl.TextSize = lbl.TextSize / access.GetUserFontScale + 5.5
                End If
                
            Else
                lbl.TextSize = lbl.TextSize / access.GetUserFontScale + 2
            End If
        Else If v Is Spinner Then
            Dim s As Spinner = v
            'De acuerdo a la escala de configuración del dispositivo determino los tamaños de texto:
            s.TextSize = s.TextSize / access.GetUserFontScale
        Else If v Is Button Then
            Dim b As Button = v
            'De acuerdo a la escala de configuración del dispositivo determino los tamaños de texto:
            If lytValores.Scale < 2 Then
                b.TextSize = b.TextSize / access.GetUserFontScale + 4
            Else
                b.TextSize = b.TextSize / access.GetUserFontScale + 2
            End If
            b.TextSize=b.TextSize / access.GetUserFontScale + 2
        End If
    Next
End Sub

Sub Escalar(p As Panel)
    Dim escala As Float
    escala=lytValores.Scale
    
    Dim wDip,hDip As Float

    wDip=lytValores.Width/lytValores.Scale 'Obtengo ancho: pixel/escala=dips
    hDip=lytValores.Height/lytValores.Scale  'Obtengo alto: pixel/escala=dips
    
    Dim rX,rY As Float
    rX=wDip/360 'Obtengo el factor de escala ancho dips / ancho variante
    rY=hDip/640 'Obtengo el factor de escala alto dips / alto variante

    'Todo el calculo siguiente se realiza porque el código ubica todos los controles en base al ancho
    'en pixeles real del dispositivo (en mi caso 720 pixeles en ancho) y alto (1280px o 1199px)
    'De tener el porcentaje del control en la variante, lo paso a pixeles en el dispositivo
'    If p=pnlPagina1 Or p=pnlPagina2 Or p=pnlPagina3 Or p=pnlPagina4 Then 'Para el tabstrip, necesito individualizar los paneles
'        Dim v As View
'        Dim l As Float 'Variable auxiliar
'   
'        v=p
'        l=(((V.Left/escala)*rX)/wDip)*100 'Obtengo un porcentaje de izquierda /escala dispositivo por factor de escala ancho/ancho en ancho dips total
'        V.Left=(((l*wDip)/100)*escala)  'desde el porcentaje, calculo la cantidad de pixeles de izquierda
'   
'        l=(((V.Top/escala)*rY)/hDip)*100 'Porcentaje de arriba
'        V.Top=(((l*hDip)/100)*escala) 'cantidad de pixeles desde arriba
'   
'        l=(((V.Width/escala)*rX)/wDip)*100 'Porcentaje de ancho
'        V.Width=(((l*wDip)/100)*escala)+16 'Cantidad de pixeles en ancho
'   
'        l=(((V.Height/escala)*rY)/hDip)*100 'porcentaje alto
'        V.Height=((l*hDip)/100)*escala +36dip 'cantidad de pixeles en alto
'    End If
    
    For Each V As View In p
        If V Is Panel Then
            Dim l As Float 'Variable auxiliar
    
            l=(((V.Left/escala)*rX)/wDip)*100 'Obtengo un porcentaje de izquierda /escala dispositivo por factor de escala ancho/ancho en ancho dips total
            V.Left=(((l*wDip)/100)*escala)  'desde el porcentaje, calculo la cantidad de pixeles de izquierda
    
            l=(((V.Top/escala)*rY)/hDip)*100 'Porcentaje de arriba
            V.Top=(((l*hDip)/100)*escala) 'cantidad de pixeles desde arriba
    
            l=(((V.Width/escala)*rX)/wDip)*100 'Porcentaje de ancho
            V.Width=(((l*wDip)/100)*escala) 'Cantidad de pixeles en ancho
    
            l=(((V.Height/escala)*rY)/hDip)*100 'porcentaje alto
            V.Height=((l*hDip)/100)*escala 'cantidad de pixeles en alto
            '-------
            Escalar(v)
        
        Else
        
            Dim l As Float 'Variable auxiliar
    
            l=(((V.Left/escala)*rX)/wDip)*100 'Obtengo un porcentaje de izquierda /escala dispositivo por factor de escala ancho/ancho en ancho dips total
            V.Left=(((l*wDip)/100)*escala)  'desde el porcentaje, calculo la cantidad de pixeles de izquierda
    
            l=(((V.Top/escala)*rY)/hDip)*100 'Porcentaje de arriba
            V.Top=(((l*hDip)/100)*escala) 'cantidad de pixeles desde arriba
    
            l=(((V.Width/escala)*rX)/wDip)*100 'Porcentaje de ancho
            V.Width=(((l*wDip)/100)*escala) 'Cantidad de pixeles en ancho
    
            l=(((V.Height/escala)*rY)/hDip)*100 'porcentaje alto
            V.Height=((l*hDip)/100)*escala 'cantidad de pixeles en alto
            '-------
        
        End If
        
    Next
    
    '-------
End Sub

Sub btnEscanear_Click
    QRCodeReaderView1.Visible = True
    DoEvents
    QRCodeReaderView1.startScan
    
End Sub



Sub LectorQR_result_found(retval As String)
'    Activity.RemoveAllViews
'    Activity.LoadLayout("ResultadoQR")
'    lytValores=GetDeviceLayoutValues
'    Escalar(Activity)
'    ResetUserFontScale(Activity)
    Log("B4A: " & retval)
    Label1.Text=retval
'    lblResultado.Text = retval
End Sub
 

biometrics

Active Member
Licensed User
Longtime User
Hello! I made a project with your library. I tried to do the same steps like in the example project but when I start scanning in my project the scanner seems to be not working. but with the same QR code in the example project it works. Perhaps I'm doing something wrong?

B4X:
#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: False
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    'These variables can be accessed from all modules.
    Private xui As XUI
    Dim access As Accessiblity 'Variable de la accesibilidad del usuario
    Private lytValores As LayoutValues
   
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 LectorQR As QRCodesReaderView
    Private btnEscanear As Button
'    Private lblResultado As Label
    Private QRCodeReaderView1 As QRCodeReaderView
    Private lblResultado As Label
    Private Label1 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("Lector")
    lytValores=GetDeviceLayoutValues
    Escalar(Activity)
    ResetUserFontScale(Activity)
'  
    QRCodeReaderView1.Visible = False

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub ResetUserFontScale(p As Panel)
    'Reconfigurar tamaño de fuente del dispositivo, impedir que se escale
    ' For Each v As View In activity.GetAllViewsRecursive
'    For Each v As View In p
    For Each v As View In p
        If v Is Panel Then
            ResetUserFontScale(v)
        Else If v Is Label Then
            Dim lbl As Label = v
            'De acuerdo a la escala de configuración del dispositivo determino los tamaños de texto:
            If lytValores.Scale <= 1 Then
                lbl.TextSize = lbl.TextSize / access.GetUserFontScale + 12
            Else If lytValores.Scale < 2 Then
                If lbl.TextSize<=14 Then
                    lbl.TextSize = lbl.TextSize / access.GetUserFontScale + 3.5
                Else
                    lbl.TextSize = lbl.TextSize / access.GetUserFontScale + 5.5
                End If
               
            Else
                lbl.TextSize = lbl.TextSize / access.GetUserFontScale + 2
            End If
        Else If v Is Spinner Then
            Dim s As Spinner = v
            'De acuerdo a la escala de configuración del dispositivo determino los tamaños de texto:
            s.TextSize = s.TextSize / access.GetUserFontScale
        Else If v Is Button Then
            Dim b As Button = v
            'De acuerdo a la escala de configuración del dispositivo determino los tamaños de texto:
            If lytValores.Scale < 2 Then
                b.TextSize = b.TextSize / access.GetUserFontScale + 4
            Else
                b.TextSize = b.TextSize / access.GetUserFontScale + 2
            End If
            b.TextSize=b.TextSize / access.GetUserFontScale + 2
        End If
    Next
End Sub

Sub Escalar(p As Panel)
    Dim escala As Float
    escala=lytValores.Scale
   
    Dim wDip,hDip As Float

    wDip=lytValores.Width/lytValores.Scale 'Obtengo ancho: pixel/escala=dips
    hDip=lytValores.Height/lytValores.Scale  'Obtengo alto: pixel/escala=dips
   
    Dim rX,rY As Float
    rX=wDip/360 'Obtengo el factor de escala ancho dips / ancho variante
    rY=hDip/640 'Obtengo el factor de escala alto dips / alto variante

    'Todo el calculo siguiente se realiza porque el código ubica todos los controles en base al ancho
    'en pixeles real del dispositivo (en mi caso 720 pixeles en ancho) y alto (1280px o 1199px)
    'De tener el porcentaje del control en la variante, lo paso a pixeles en el dispositivo
'    If p=pnlPagina1 Or p=pnlPagina2 Or p=pnlPagina3 Or p=pnlPagina4 Then 'Para el tabstrip, necesito individualizar los paneles
'        Dim v As View
'        Dim l As Float 'Variable auxiliar
'  
'        v=p
'        l=(((V.Left/escala)*rX)/wDip)*100 'Obtengo un porcentaje de izquierda /escala dispositivo por factor de escala ancho/ancho en ancho dips total
'        V.Left=(((l*wDip)/100)*escala)  'desde el porcentaje, calculo la cantidad de pixeles de izquierda
'  
'        l=(((V.Top/escala)*rY)/hDip)*100 'Porcentaje de arriba
'        V.Top=(((l*hDip)/100)*escala) 'cantidad de pixeles desde arriba
'  
'        l=(((V.Width/escala)*rX)/wDip)*100 'Porcentaje de ancho
'        V.Width=(((l*wDip)/100)*escala)+16 'Cantidad de pixeles en ancho
'  
'        l=(((V.Height/escala)*rY)/hDip)*100 'porcentaje alto
'        V.Height=((l*hDip)/100)*escala +36dip 'cantidad de pixeles en alto
'    End If
   
    For Each V As View In p
        If V Is Panel Then
            Dim l As Float 'Variable auxiliar
   
            l=(((V.Left/escala)*rX)/wDip)*100 'Obtengo un porcentaje de izquierda /escala dispositivo por factor de escala ancho/ancho en ancho dips total
            V.Left=(((l*wDip)/100)*escala)  'desde el porcentaje, calculo la cantidad de pixeles de izquierda
   
            l=(((V.Top/escala)*rY)/hDip)*100 'Porcentaje de arriba
            V.Top=(((l*hDip)/100)*escala) 'cantidad de pixeles desde arriba
   
            l=(((V.Width/escala)*rX)/wDip)*100 'Porcentaje de ancho
            V.Width=(((l*wDip)/100)*escala) 'Cantidad de pixeles en ancho
   
            l=(((V.Height/escala)*rY)/hDip)*100 'porcentaje alto
            V.Height=((l*hDip)/100)*escala 'cantidad de pixeles en alto
            '-------
            Escalar(v)
       
        Else
       
            Dim l As Float 'Variable auxiliar
   
            l=(((V.Left/escala)*rX)/wDip)*100 'Obtengo un porcentaje de izquierda /escala dispositivo por factor de escala ancho/ancho en ancho dips total
            V.Left=(((l*wDip)/100)*escala)  'desde el porcentaje, calculo la cantidad de pixeles de izquierda
   
            l=(((V.Top/escala)*rY)/hDip)*100 'Porcentaje de arriba
            V.Top=(((l*hDip)/100)*escala) 'cantidad de pixeles desde arriba
   
            l=(((V.Width/escala)*rX)/wDip)*100 'Porcentaje de ancho
            V.Width=(((l*wDip)/100)*escala) 'Cantidad de pixeles en ancho
   
            l=(((V.Height/escala)*rY)/hDip)*100 'porcentaje alto
            V.Height=((l*hDip)/100)*escala 'cantidad de pixeles en alto
            '-------
       
        End If
       
    Next
   
    '-------
End Sub

Sub btnEscanear_Click
    QRCodeReaderView1.Visible = True
    DoEvents
    QRCodeReaderView1.startScan
   
End Sub



Sub LectorQR_result_found(retval As String)
'    Activity.RemoveAllViews
'    Activity.LoadLayout("ResultadoQR")
'    lytValores=GetDeviceLayoutValues
'    Escalar(Activity)
'    ResetUserFontScale(Activity)
    Log("B4A: " & retval)
    Label1.Text=retval
'    lblResultado.Text = retval
End Sub
I'm not sure what is wrong but here is the essentials parts of my code:

B4X:
Sub Globals
  Dim libQRCodeReaderView As QRCodeReaderView
  Dim pnlQRCodeReaderView As Panel
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    If libQRCodeReaderView.IsInitialized Then
        libQRCodeReaderView.stopScan
    End If
End Sub

Sub QRCodeScan
    Activity.LoadLayout("frmQRCodeScanner")
    
    '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(libQRCodeReaderView.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(libQRCodeReaderView.FrontFacingCamera)
    Log(libQRCodeReaderView.CAMERA_BACK)
    Log(libQRCodeReaderView.CAMERA_FRONT)

    libQRCodeReaderView.CameraId = libQRCodeReaderView.CAMERA_BACK
    libQRCodeReaderView.ScanNow = True
    pnlQRCodeReaderView.Visible = True
    libQRCodeReaderView.Visible = True
    
    DoEvents
    libQRCodeReaderView.startScan
End Sub

Sub libQRCodeReaderView_result_found(retval As String)
  Log(retval)
  libQRCodeReaderView.stopScan
  pnlQRCodeReaderView.Visible = False
  libQRCodeReaderView.Visible = False
End Sub

Note that libQRCodeReaderView is a child of pnlQRCodeReaderView in the Designer.

And the manifest:

B4X:
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="false" />)
AddPermission("android.permission.INTERNET")
AddPermission("android.permission.ACCESS_FINE_LOCATION")
AddPermission("android.permission.WAKE_LOCK")
AddPermission("android.permission.DEVICE_POWER")
AddPermission("android.permission.READ_PHONE_STATE")
AddPermission("android.permission.VIBRATE")
AddPermission("android.permission.CAMERA")
AddPermission("android.permission.FLASHLIGHT")
AddPermission("android.hardware.camera")

Hope that helps.
 
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
Hi, Thanks for sharing. How can I set the corner radius for this custom view?
I need to use it and set a corner radius to have a good user-friendly experience.

Best Regards.
 

Johan Schoeman

Expert
Licensed User
Longtime User
Hi, Thanks for sharing. How can I set the corner radius for this custom view?
I need to use it and set a corner radius to have a good user-friendly experience.

Best Regards.
QRCodeReaderView extends SurfaceView. SurfaceView does not have a property to set the corner radius of a SurfaceView - from what I can gather from the web.
 

ganezha

Member
I tried uploading to playstore with targetSdkVersion=31. But it was rejected by playstore as follows "You uploaded an APK or Android App Bundle which has an activity, activity alias, service or broadcast receiver with intent filter, but without 'android:exported' property set."

Please help where is the error?
Thanks in advance for the help

manifest editor
manifest editor:
'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: http://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="31"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
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="false" />)
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.hardware.camera")
AddPermission("android.permission.VIBRATE")
AddPermission("android.permission.CAMERA")
AddPermission("android.permission.FLASHLIGHT")
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
 

Johan Schoeman

Expert
Licensed User
Longtime User
B4X:
I tried uploading to playstore with targetSdkVersion=31. But it was rejected by playstore as follows "You uploaded an APK or Android App Bundle which has an activity, activity alias, service or broadcast receiver with intent filter, but without 'android:exported' property set."

Please help where is the error?
Thanks in advance for the help

No idea...
 

ganezha

Member
B4X:
I tried uploading to playstore with targetSdkVersion=31. But it was rejected by playstore as follows "You uploaded an APK or Android App Bundle which has an activity, activity alias, service or broadcast receiver with intent filter, but without 'android:exported' property set."

Please help where is the error?
Thanks in advance for the help

No idea...


I also tried your library this one
https://www.b4x.com/android/forum/t...other-barcode-scanner-that-is-100-embedded-in -b4a.63764/
When uploading playstore the error is the same :) which property should be set ? have you tried to upload it to playstore with SDK=31 ? 🙏
 

Johan Schoeman

Expert
Licensed User
Longtime User
I also tried your library this one
https://www.b4x.com/android/forum/t...other-barcode-scanner-that-is-100-embedded-in -b4a.63764/
When uploading playstore the error is the same :) which property should be set ? have you tried to upload it to playstore with SDK=31 ? 🙏
See here
 

ganezha

Member
See here
Still with the same error, I'm still new to programming. Ask for help and direction. maybe I was wrong in entering the manifest. Thanks in advance for your help :) 🙏
Here I send the file, to help you correct it
 

Attachments

  • b4aZxingBarcodeScanner.rar
    14.3 KB · Views: 114

Johan Schoeman

Expert
Licensed User
Longtime User
Still with the same error, I'm still new to programming. Ask for help and direction. maybe I was wrong in entering the manifest. Thanks in advance for your help :) 🙏
Here I send the file, to help you correct it
You should maybe open a new thread for this issue. There will be forum members that should be able to help you with this problem. I have no apps on the play store so cannot help you with this.
 

Johan Schoeman

Expert
Licensed User
Longtime User
Still with the same error, I'm still new to programming. Ask for help and direction. maybe I was wrong in entering the manifest. Thanks in advance for your help :) 🙏
Here I send the file, to help you correct it
Maybe something like this

B4X:
AddApplicationText(
  <provider
  android:name="android.support.v4.content.FileProvider"
  android:authorities="$PACKAGE$.provider"
  android:exported="false"
  android:grantUriPermissions="true">
  <meta-data
  android:name="android.support.FILE_PROVIDER_PATHS"
  android:resource="@xml/provider_paths"/>
  </provider>
 

ganezha

Member
Maybe something like this

B4X:
AddApplicationText(
  <provider
  android:name="android.support.v4.content.FileProvider"
  android:authorities="$PACKAGE$.provider"
  android:exported="false"
  android:grantUriPermissions="true">
  <meta-data
  android:name="android.support.FILE_PROVIDER_PATHS"
  android:resource="@xml/provider_paths"/>
  </provider>
Dear Johan, still with the same error :) 🙏
I have changed the manifest as below
Have you tried uploading it yourself to the playstore?

manifest editor:
AddManifestText(
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="31"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
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="false" />)   
AddPermission("android.permission.WAKE_LOCK")
AddPermission("android.permission.DEVICE_POWER")
'AddPermission("android.permission.READ_PHONE_STATE")
AddPermission("android.permission.VIBRATE")
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
AddApplicationText(
  <provider
  android:name="android.support.v4.content.FileProvider"
  android:authorities="$PACKAGE$.provider"
  android:exported="false"
  android:grantUriPermissions="true">
  <meta-data
  android:name="android.support.FILE_PROVIDER_PATHS"
  android:resource="@xml/provider_paths"/>
  </provider>
  )
  CreateResource(xml, provider_paths,
   <files-path name="name" path="shared" />
)
 

james_sgp

Active Member
Licensed User
Longtime User
Using your latest version of this library and its working well on Galaxy S8+, scans with a couple of seconds. But on Galaxy A22 it seems to have problems focusing and you have to pull the phone back off the QR code to make it work, and even then its slower? Is there a way to force an auto focus?.

James

EDIT : After some thought n checking, the A22 has multiple rear cameras (S8+) doesn`t...how do i select one of them?
 

Dwnr80

New Member
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.
 
Top