B4A Library Barcode Scanner - 100% embedded within B4A (15 Feb 2016 : New library files in Post #105)

The attached project wraps this Github project. It is a barcode scanner based on the ZXING project. I have successfully scanned the following 1D and 2D barcodes:
1. Code 39
2. Code 93
3. Code 128
4. Two-of-Five Interleaved (TFI)
5. EAN13
6. EAN8
7. PDF417
8. QR Code
9. Aztec Code
10. Codabar

It is 100% embedded within the B4A project via a CustomView. Thus, you can add buttons, background images, background colors, labels, textviews, or whatever you like to the activity via the designer or via code. It does not have all the bells and whistles that the ZXING project offers (i.e ability to set the laser color etc) but it works 100% within B4A. It does not take over control of the B4A activity - set the size (width / height / left / top) of the CustomView in the B4A code and that will be the size of your barcode View Finder. Add buttons to start and stop the scanner. It is as simple as that.

For as long as what the scanner is active it will scan 1D/2D barcodes i.e no need to stop and start the scanner to start scanning a new barcode. Just point the scanner at the next barcode to scan.

I have added the following events to the B4A project:
1. scanresult - here you can get the decoded string/text result when a successful scan occurred
2. scanner_started - this event is raised when the scanner is activated via B4A code
3. scan_error - sorry, but have not seen this event in action yet as I have had no miss scans thus far
4. scanner_stopped - this event is raised when the scanner is stopped.

There are a number of files in the B4A project's Object/res/..... folders that are set to read only. Keep them like that.

There are permissions added to the B4A manifest - make sure you take note of it should you start a new B4A project.

You will need core-3.1.0.jar and android-support-v4.jar to be in your additional library folder. I have zipped them together - you can download them from HERE. Extract them from the zipped file and copy them to your additional library folder.

1.png


2.png


Some sample code:

B4X:
#Region  Project Attributes
    #ApplicationLabel: zxScannerLiveView
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: landscape
    #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 zxslv As zxScannerLiveView
    Private b1 As Button
    Private b2 As Button
    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")

    zxslv.Initialize("zxslv")

    Activity.AddView(zxslv, 50%x - 45%y, 5%y, 90%y, 90%y)

    zxslv.HudVisible = True
    zxslv.PlaySound = True
    zxslv.Visible = False

End Sub

Sub Activity_Resume


End Sub

Sub Activity_Pause (UserClosed As Boolean)

    zxslv.Visible = False
    zxslv.stopScanner

End Sub

Sub b1_Click

    zxslv.Visible = True
    zxslv.startScanner

End Sub
Sub b2_Click

    zxslv.Visible = False
    zxslv.stopScanner
    l1.Text = ""

End Sub

Sub zxslv_scanresult

    Log(zxslv.ScanResult)
    l1.Text = zxslv.ScanResult

End Sub

Sub zxslv_scanner_started

    Log("Scanner Started")

End Sub

Sub zxslv_scan_error

    Log("Scan Error")

End Sub

Sub zxslv_scanner_stopped

    Log("Scanner stopped")

End Sub


And this will add a coloured frame around the view finder - making use of panels via B4A code:

B4X:
#Region  Project Attributes
    #ApplicationLabel: zxScannerLiveView
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: landscape
    #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 zxslv As zxScannerLiveView
    Private b1 As Button
    Private b2 As Button
    Private l1 As Label
    Private l2, l3, l4, l5 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")

    zxslv.Initialize("zxslv")
    Dim framecolor As Int = Colors.Red

    l2.Initialize("")
    l3.Initialize("")
    l4.Initialize("")
    l5.Initialize("")

    Activity.AddView(zxslv, 50%x - 45%y, 5%y, 90%y, 90%y)
    Activity.AddView(l2, 50%x - 45%y - 1%y, 4%y, 1%y, 92%y)
    Activity.AddView(l3, 50%x + 45%y, 4%y, 1%y, 92%y)
    Activity.AddView(l4, 50%x - 45%y - 1%y, 4%y, 91%y, 1%y)
    Activity.AddView(l5, 50%x - 45%y - 1%y, 5%y + 90%y, 91%y, 1%y)


    l2.Color = framecolor
    l2.Visible = False

    l3.Color = framecolor
    l3.Visible = False

    l4.Color = framecolor
    l4.Visible = False

    l5.Color = framecolor
    l5.Visible = False

    zxslv.HudVisible = True
    zxslv.PlaySound = True
    zxslv.Visible = False


End Sub

Sub Activity_Resume


End Sub

Sub Activity_Pause (UserClosed As Boolean)

    zxslv.Visible = False
    zxslv.stopScanner

    l2.Visible = False
    l3.Visible = False
    l4.Visible = False
    l5.Visible = False

End Sub

Sub b1_Click

    zxslv.Visible = True
    zxslv.startScanner

    l2.Visible = True
    l3.Visible = True
    l4.Visible = True
    l5.Visible = True

End Sub
Sub b2_Click

    zxslv.Visible = False
    zxslv.stopScanner
    l1.Text = ""

    l2.Visible = False
    l3.Visible = False
    l4.Visible = False
    l5.Visible = False



End Sub

Sub zxslv_scanresult

    Log(zxslv.ScanResult)
    l1.Text = zxslv.ScanResult

End Sub

Sub zxslv_scanner_started

    Log("Scanner Started")

End Sub

Sub zxslv_scan_error

    Log("Scan Error")

End Sub

Sub zxslv_scanner_stopped

    Log("Scanner stopped")

End Sub

It will look like this:

3.png


zxScannerLiveView
Author: Github: Dmitri Livotov, Wrapper: Johan Schoeman
Version: 1



zxScannerLiveView
Events:

  • scan_error ( )
  • scanner_started ( )
  • scanner_stopped ( )
  • scanresult ( )
Fields:
  • BACK As String
  • FRONT As String
  • ba As BA
  • mfrontOrBack As String
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)
  • startScanner
    Starts scanner, using device default camera
  • stopScanner
    Stops currently running scanner
  • toggleFlash
Properties:
  • BackgroudImage As String [write only]
  • Background As Drawable
  • CameraToUse As String [write only]
  • Color As Int [write only]
  • Enabled As Boolean
  • Height As Int
  • HudVisible As Boolean [write only]
  • Left As Int
  • PlaySound As Boolean [write only]
  • SameCodeRescanProtectionTime As Long [write only]
  • ScanResult As String [read only]
  • 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

  • zxScannerLiveViewLibFiles.zip
    44.9 KB · Views: 3,342
  • b4aZXscannerLiveView.zip
    19 KB · Views: 3,278
Last edited:

Johan Schoeman

Expert
Licensed User
Longtime User
Hello! I've the Basic4Android v3.5 and I've problems when my app loads the line zxslv.Initialize("zxslv"). Somebody can help me?
Thanks.
Please post the error that you get - the dump in the B4A log.
 

fabio borges

Member
Licensed User
Longtime User
Hello Johan,

Just tested your library, works fine on a Moto X, however, on a tablet with Jelly Bean doesn't, it calls scan error event repeatedly.
Any idea why?
Thanks!
 

Attachments

  • Screenshot_2015-12-22-16-06-14.png
    Screenshot_2015-12-22-16-06-14.png
    17.8 KB · Views: 285

Johan Schoeman

Expert
Licensed User
Longtime User
Hello Johan,

Just tested your library, works fine on a Moto X, however, on a tablet with Jelly Bean doesn't, it calls scan error event repeatedly.
Any idea why?
Thanks!
Not really - I am running it on Ice Cream Sandwich and KitKat (Jelly Bean is smack in between) and on both devices it works fine. Are you using front or back camera on your tablet and does it have both a front and back camera?
 

fabio borges

Member
Licensed User
Longtime User
Not really - I am running it on Ice Cream Sandwich and KitKat (Jelly Bean is smack in between) and on both devices it works fine. Are you using front or back camera on your tablet and does it have both a front and back camera?

Found a solution. Removed some permissions at manifest and worked, not sure which was causing the problem.
Have you found problems reading EAN-13? Takes to much effort to detect.
 

Johan Schoeman

Expert
Licensed User
Longtime User
Found a solution. Removed some permissions at manifest and worked, not sure which was causing the problem.
Have you found problems reading EAN-13? Takes to much effort to detect.
I have not experienced too much of an issue when scanning barcode with the front or back camera including EAN-13. But if you want to try something else then you could give QRCPV4 a go that you can find here:

https://www.b4x.com/android/forum/threads/qr-code-library.41408/#post-259448
 
Last edited:

JDS

Active Member
Licensed User
Longtime User
The example is failing at
B4X:
zxslv.Initialize("zxslv")
I'm using 5.50 of B4A, core 4.92

Any thoughts?

Error:

B4X:
Error occurred on line: 41 (Main)
android.content.res.Resources$NotFoundException: Resource ID #0x0
    at android.content.res.Resources.getValue(Resources.java:1307)
    at android.content.res.Resources.loadXmlResourceParser(Resources.java:2871)
    at android.content.res.Resources.getLayout(Resources.java:1123)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:412)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
    at eu.livotov.labs.android.camview.ScannerLiveView.initUI(ScannerLiveView.java:58)
    at eu.livotov.labs.android.camview.ScannerLiveView.<init>(ScannerLiveView.java:53)
    at zxscanwrapper.zxScanWrapper._initialize(zxScanWrapper.java:88)
    at zxscanwrapper.zxScanWrapper.Initialize(zxScanWrapper.java:81)
    at JHS.zxScannerLiveView.main._activity_create(main.java:369)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:697)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:339)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:246)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
    at JHS.zxScannerLiveView.main.afterFirstLayout(main.java:102)
    at JHS.zxScannerLiveView.main.access$000(main.java:17)
    at JHS.zxScannerLiveView.main$WaitForLayout.run(main.java:80)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:211)
    at android.app.ActivityThread.main(ActivityThread.java:5389)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1020)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:815)
** Activity (main) Resume **
 

Johan Schoeman

Expert
Licensed User
Longtime User
The example is failing at
B4X:
zxslv.Initialize("zxslv")
I'm using 5.50 of B4A, core 4.92

Any thoughts?

Error:

It is not related to B4A 5.50. I am using the same version of B4A. Do you have all the folders and files in the Objects/res folder? Seems like you might be missing some of the resources that the project makes use of

1.png
 

Johan Schoeman

Expert
Licensed User
Longtime User
The example is failing at
B4X:
zxslv.Initialize("zxslv")
I'm using 5.50 of B4A, core 4.92

Any thoughts?

Error:

....also, did you download core-3.1.0.jar and android-support-v4.jar from the link that I have posted in post #1 and added them to your additional library folder?
 

JDS

Active Member
Licensed User
Longtime User
No at the map /res/
I've only have the folders:
drawable
layout
xml

However, this is the example-zip. Aren't those included or created by B4a?
 

Johan Schoeman

Expert
Licensed User
Longtime User
No at the map /res/
I've only have the folders:
drawable
layout
xml

However, this is the example-zip. Aren't those included or created by B4a?
Attached is the res folder of the B4A project - replace your project's res folder with this
 

Attachments

  • res.zip
    42.5 KB · Views: 408

Johan Schoeman

Expert
Licensed User
Longtime User
No at the map /res/
I've only have the folders:
drawable
layout
xml

However, this is the example-zip. Aren't those included or created by B4a?
I have just downloaded every B4A project that I have posted in this thread and they ALL have the correct /res folder. You will only have the 3 folders that you mentioned in post #72 if you stated a new project.
 

JDS

Active Member
Licensed User
Longtime User
Correct. But when running B4A deletes the others.
I've set the other folders (from post 74) to "read only" then the error disappeares (read somewhere in the topic).

Strange behaviour. Works now. Thanks for the help!
 

Yayou49

Active Member
Licensed User
Hi,
I have a problem to understand the syntax of the settings of the view.
When you set:
B4X:
Activity.AddView(zxslv, 50%x - 45%y, 5%y, 90%y, 90%y)
It seems values are for width/height/left/top as describe in your description post #1

I don't understand the meaning of "%" and "x" and "y"
Also, I don't understand the "50%x - 45%y"

Thanks in advance for your answer.
 

Johan Schoeman

Expert
Licensed User
Longtime User
Hi,
I have a problem to understand the syntax of the settings of the view.
When you set:
B4X:
Activity.AddView(zxslv, 50%x - 45%y, 5%y, 90%y, 90%y)
It seems values are for width/height/left/top as describe in your description post #1

I don't understand the meaning of "%" and "x" and "y"
Also, I don't understand the "50%x - 45%y"

Thanks in advance for your answer.
x = width of the activity in this case (or that of the parent view)
y = height of the activity in this case (or that of the parent view)
% = what % of the width or height you want the view to be relative to that of the parent view (i.e the activity in this case)

50%x = the centre point of the parent activity in the x direction
50%x - 45%y = I want the view to be 90%y in height. But I want it to be square and therefore I have the width as 90%y too
So, 50%x - 45% y will give me the centre point along the x direction and I will end up with a square view that has a width and height of 90%y but that is centred around the centre point of the activity in the x direction. The top will however be at 5%y (i.e 5% of the height of the parent view which in this case is the height of the activity)
 
Last edited:

Yayou49

Active Member
Licensed User
Many thanks for your prompt answer, it's quite clear now.

In my project, I've added a new Activity (called "Scan") to implement your scan reader. (see my code at the end of this message)

A problem occur at line 29:
B4X:
zxslv.Initialize("zxslv")

I've got this error message and I don't understand what can be the problem and how to solve it :

B4X:
Error occurred on line: 29 (Scan)
android.content.res.Resources$NotFoundException: Resource ID #0x0
    at android.content.res.Resources.getValue(Resources.java:1351)
    at android.content.res.Resources.loadXmlResourceParser(Resources.java:2774)
    at android.content.res.Resources.getLayout(Resources.java:1165)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:421)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
    at eu.livotov.labs.android.camview.ScannerLiveView.initUI(ScannerLiveView.java:72)
    at eu.livotov.labs.android.camview.ScannerLiveView.<init>(ScannerLiveView.java:67)
    at zxscanwrapper.zxScanWrapper._initialize(zxScanWrapper.java:79)
    at zxscanwrapper.zxScanWrapper.Initialize(zxScanWrapper.java:72)
    at b4a.example.scan._activity_create(scan.java:345)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:697)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:339)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:246)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
    at b4a.example.scan.afterFirstLayout(scan.java:102)
    at b4a.example.scan.access$000(scan.java:17)
    at b4a.example.scan$WaitForLayout.run(scan.java:80)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:148)
    at android.app.ActivityThread.main(ActivityThread.java:5417)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

Hereafter my full code for this 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.
   
    Public ScanSN As String

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 zxslv As zxScannerLiveView
    Private l1,l2, l3, l4 As Label
    Private scanStarted As Boolean = False

End Sub

Sub Activity_Create(FirstTime As Boolean)
   
    Activity.LoadLayout("scan")
   
    'initialisation du scanner
    zxslv.Initialize("zxslv")
    Dim framecolor As Int = Colors.Red
   
    l1.Initialize("")
    l2.Initialize("")
    l3.Initialize("")
    l4.Initialize("")
   
    Activity.AddView(zxslv, 50%x - 45%y, 5%y, 90%y, 90%y)
    Activity.AddView(l1, 50%x - 45%y - 1%y, 4%y, 1%y, 92%y)
    Activity.AddView(l2, 50%x + 45%y, 4%y, 1%y, 92%y)
    Activity.AddView(l3, 50%x - 45%y - 1%y, 4%y, 91%y, 1%y)   
    Activity.AddView(l4, 50%x - 45%y - 1%y, 5%y + 90%y, 91%y, 1%y)       
   
   
    l1.Color = framecolor
    l1.Visible = False
   
    l2.Color = framecolor
    l2.Visible = False
   
    l3.Color = framecolor
    l3.Visible = False   
   
    l4.Color = framecolor
    l4.Visible = False

    zxslv.HudVisible = True
    zxslv.PlaySound = True
    zxslv.Visible = False
   
    'demarrage du scanner
    zxslv.Visible = True
    zxslv.startScanner
   
    l1.Visible = True
    l2.Visible = True
    l3.Visible = True
    l4.Visible = True       
   
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)
zxslv.Visible = False
    zxslv.stopScanner
   
    l1.Visible = False
    l2.Visible = False
    l3.Visible = False   
    l4.Visible = False       
   
End Sub

Sub zxslv_scanresult
   
    Log(zxslv.ScanResult)
    ScanSN = zxslv.ScanResult
   
End Sub

Sub BtStopScan_Click
   
    'ScanSN = zxslv.ScanResult
   
    zxslv.Visible = False
    zxslv.stopScanner
       
    l1.Visible = False
    l2.Visible = False
    l3.Visible = False
    l4.Visible = False   
       
   
End Sub

Sub BtTorche_Click
    If scanStarted = True Then
      zxslv.toggleFlash
    End If 
End Sub

Sub zxslv_scanner_started
   
    scanStarted = True
    Log("Scanner Started")
   
End Sub

Sub zxslv_scan_error
   
    Log("Scan Error")
   
End Sub

Sub zxslv_scanner_stopped
    scanStarted = False
    Log("Scanner stopped")
   
End Sub
 

Johan Schoeman

Expert
Licensed User
Longtime User
Many thanks for your prompt answer, it's quite clear now.

In my project, I've added a new Activity (called "Scan") to implement your scan reader. (see my code at the end of this message)

A problem occur at line 29:
B4X:
zxslv.Initialize("zxslv")

I've got this error message and I don't understand what can be the problem and how to solve it :

B4X:
Error occurred on line: 29 (Scan)
android.content.res.Resources$NotFoundException: Resource ID #0x0
    at android.content.res.Resources.getValue(Resources.java:1351)
    at android.content.res.Resources.loadXmlResourceParser(Resources.java:2774)
    at android.content.res.Resources.getLayout(Resources.java:1165)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:421)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
    at eu.livotov.labs.android.camview.ScannerLiveView.initUI(ScannerLiveView.java:72)
    at eu.livotov.labs.android.camview.ScannerLiveView.<init>(ScannerLiveView.java:67)
    at zxscanwrapper.zxScanWrapper._initialize(zxScanWrapper.java:79)
    at zxscanwrapper.zxScanWrapper.Initialize(zxScanWrapper.java:72)
    at b4a.example.scan._activity_create(scan.java:345)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:697)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:339)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:246)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
    at b4a.example.scan.afterFirstLayout(scan.java:102)
    at b4a.example.scan.access$000(scan.java:17)
    at b4a.example.scan$WaitForLayout.run(scan.java:80)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:148)
    at android.app.ActivityThread.main(ActivityThread.java:5417)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

Hereafter my full code for this 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.
  
    Public ScanSN As String

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 zxslv As zxScannerLiveView
    Private l1,l2, l3, l4 As Label
    Private scanStarted As Boolean = False

End Sub

Sub Activity_Create(FirstTime As Boolean)
  
    Activity.LoadLayout("scan")
  
    'initialisation du scanner
    zxslv.Initialize("zxslv")
    Dim framecolor As Int = Colors.Red
  
    l1.Initialize("")
    l2.Initialize("")
    l3.Initialize("")
    l4.Initialize("")
  
    Activity.AddView(zxslv, 50%x - 45%y, 5%y, 90%y, 90%y)
    Activity.AddView(l1, 50%x - 45%y - 1%y, 4%y, 1%y, 92%y)
    Activity.AddView(l2, 50%x + 45%y, 4%y, 1%y, 92%y)
    Activity.AddView(l3, 50%x - 45%y - 1%y, 4%y, 91%y, 1%y)  
    Activity.AddView(l4, 50%x - 45%y - 1%y, 5%y + 90%y, 91%y, 1%y)      
  
  
    l1.Color = framecolor
    l1.Visible = False
  
    l2.Color = framecolor
    l2.Visible = False
  
    l3.Color = framecolor
    l3.Visible = False  
  
    l4.Color = framecolor
    l4.Visible = False

    zxslv.HudVisible = True
    zxslv.PlaySound = True
    zxslv.Visible = False
  
    'demarrage du scanner
    zxslv.Visible = True
    zxslv.startScanner
  
    l1.Visible = True
    l2.Visible = True
    l3.Visible = True
    l4.Visible = True      
  
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)
zxslv.Visible = False
    zxslv.stopScanner
  
    l1.Visible = False
    l2.Visible = False
    l3.Visible = False  
    l4.Visible = False      
  
End Sub

Sub zxslv_scanresult
  
    Log(zxslv.ScanResult)
    ScanSN = zxslv.ScanResult
  
End Sub

Sub BtStopScan_Click
  
    'ScanSN = zxslv.ScanResult
  
    zxslv.Visible = False
    zxslv.stopScanner
      
    l1.Visible = False
    l2.Visible = False
    l3.Visible = False
    l4.Visible = False  
      
  
End Sub

Sub BtTorche_Click
    If scanStarted = True Then
      zxslv.toggleFlash
    End If
End Sub

Sub zxslv_scanner_started
  
    scanStarted = True
    Log("Scanner Started")
  
End Sub

Sub zxslv_scan_error
  
    Log("Scan Error")
  
End Sub

Sub zxslv_scanner_stopped
    scanStarted = False
    Log("Scanner stopped")
  
End Sub
Read post #1 of this thread carefully. You are missing some files in the Objects/res/.... folders or if you did have them there then you have not set them to read only. Read thread #1 and make sure you have all the files where they need to be.
 
Top