B4A Library ZXingLib(integration version)by icefairy333

integration version
zxing 2.1 inside
no need to install zx scaner or other apk,just a jar and xml file copy it to b4a library dir,and then use it well.

demo:
B4X:
'Activity module
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.
Dim zx As Zxing_B4A
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("Layout1")
zx.BeginScan("myzx")
End Sub
Sub myzx_result(atype As String,Values As String)
   Log("type:"&atype&"values:"&Values)
   Msgbox("type:"&atype&"values:"&Values,"result")
End Sub
Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
and you must add last text to manifest editor:
B4X:
AddApplicationText(<activity android:name="ice.zxing.CaptureActivity"
         android:screenOrientation="landscape" android:configChanges="orientation|keyboardHidden"
         android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
         android:windowSoftInputMode="stateAlwaysHidden">
      </activity>)

lib doc:
b4aZXing
Author: IceFairy333
Version: 1.5
  • Zxing_B4A
    Events:
    • result (atype as String As , Values as String As )
    Fields:
    • isportrait As Boolean
    • useFrontCam As Boolean
    Methods:
    • BeginScan (EventName As String)
      please handle the event
      add this to manifest:<activity android:name="ice.zxing.CaptureActivity"
      android:screenOrientation="landscape" android:configChanges="orientation|keyboardHidden"
      android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
      android:windowSoftInputMode="stateAlwaysHidden"></activity>
    Permissions:
    • android.hardware.camera
    • android.hardware.camera.autofocus
    • android.permission.CAMERA
    • android.permission.FLASHLIGHT
    • android.permission.VIBRATE
    • android.permission.WRITE_EXTERNAL_STORAGE
lib doc:
b4aZXing
Author: IceFairy333
Version: 1.2
  • Zxing_B4A
    Events:
    • result (atype as String As , Values as String As )
    Methods:
    • BeginScan (EventName As String)
      please handle the event
      add this to manifest:<activity android:name="ice.zxing.CaptureActivity"
      android:screenOrientation="landscape" android:configChanges="orientation|keyboardHidden"
      android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
      android:windowSoftInputMode="stateAlwaysHidden"></activity>
    Permissions:
    • android.hardware.camera
    • android.hardware.camera.autofocus
    • android.permission.CAMERA
    • android.permission.FLASHLIGHT
    • android.permission.VIBRATE
    • android.permission.WRITE_EXTERNAL_STORAGE

anyone who has the scan twice,can download the library src to check it on your device,in my phone it works fine:signOops:

notice by Erel:The second scan happens because zx.BeginScan is called from Activity_Create. The activity is recreated when you change the orientation during the scanning.

The solution is simple. Move this call to a different sub (Button_Click for example).
 

Attachments

  • zxdemo&lib.zip
    255.5 KB · Views: 2,375
  • b4aZxingLibsrc.zip
    325.9 KB · Views: 2,040
  • b4azxing1.5.zip
    249.2 KB · Views: 2,122
Last edited:

JTmartins

Active Member
Licensed User
Longtime User
Hi,

I'm using this lib and works extremly well.

I wonder if it is possible to add an extra argument to the zx.BeginScan so that it would be zx.BeginScan(EventName, StringToDisplay, color). Then during the scan process, on the top of the screen there will be a message in the specified color.

I'm a java dumb (and Basic half dumb) so I don't know how to implement this on the java source code and recompile the lib, but I think that it would be quite simple for someone with java knowledge.

In my case QRcode is used to read codes from teachers or students, and it would be extremly helpfull to have a message so the people know if the app is waiting for teacher or student input.

I've been using other method, but it always leads to confusion amongst users. So if I could have a message there, it would be perfect.

Anyone can help me ?

Thanks
José
 
Last edited:

Gaver Powers

Member
Licensed User
Longtime User
I'm getting the following error message:
java.lang.Exception: Sub myzx_cancelled signature does not match expected signature.
When I hit the back button during a scan operation.
Anyone have any suggestions on how to correct this?

GP

I figured it out...
Canceled is more common in American English, and cancelled is more common in British English.

Sub myzx_Canceled - fails
Sub myzx_Cancelled - works :)

G
 
Last edited:

Gaver Powers

Member
Licensed User
Longtime User
Ice,Johan,Jonedan,Vpire -
The donor ZXing jar used in this library is based on ZXing version 2.1
The current version on Git is now @ 3.1.1 - I believe the newer version provides faster scanning and includes painting the corner targets to aid with alignment of the target in the window during the scan process, there may be other improvements as well.

There are now several threads going with different modifications being made to the base ZXing code.
This thread incorporated the ability to rotate the scan window to portrait mode.
Johan's thread(s) are making substantial changes to the mask and in controlling the general appearance of the scanner itself.
and in another thread - the ability to use the front camera and turn on the light was enabled.

Is there a way anyone can update the library using the latest ZXing code from Git and incorporate all of the changes from all the other threads into one library?

Also... would it be possible to add the interfaces to a ZXing fork on Git and request they be incorporated in 3.1.2?

There's a lot of oars in the water - just trying to get them all on the same boat and rowing in the same direction :)

G
 

JTmartins

Active Member
Licensed User
Longtime User
Hi everyone.

I've been playing with the sources from this lib, compiling etc...(finaly learned how to compile with Eclipse to use in B4A). I need to enable flash in torch mode, however so far all attempts have failed. The lib keeps working perfectly...but no flash light.

I'm a java noob, but I'm slowly getting my way, and with some guidance I hope to get there.

If someone can help me I would be gratefull.

Many thanks
 

canalrun

Well-Known Member
Licensed User
Longtime User
Thanks for the 1.3 plus.

I will bet you developed the demo with B4A 4.0. I'm still using 3.82. I get newer version warnings when I open the demo. Also when I run the demo the bts (raw data) variable in the result subroutine is null generating an error. If I ignore the warnings and comment out the usage of the bts variable, it works nicely.

The red line is vertical when the phone is held in portrait. For it to recognize a barcode, the red line needs to cross the width of the entire barcode – the camera must be held in landscape for a horizontally oriented barcode, or if the barcode is vertically oriented the camera must be held in portrait mode.

Is there a way to change the scanning orientation (red line) between horizontal and vertical?

In my application I need a barcode reader/decoder that operates from a stored image rather than capturing an image from the camera. Instead of calling a "begin scan" method to open the camera I would call something like "decode bitmap" passing a bitmap (or filename) as the parameter.

I need this because the phone is fixed on a tripod monitoring packages. The packages can have the barcode positioned anywhere within the camera's field of view and there may be several packages, each with a barcode. I need to isolate the barcode of interest and feed that to the decoder.

Barry.
 

Lello1964

Well-Known Member
Licensed User
Longtime User
Hello, i want use this lib, i must set my app in portrait mode, how set barcode camera in portrait mode, i have changed in manifest, but camera doesn't change.
Can you help me?
Thanks
Raffaele
 

Johan Schoeman

Expert
Licensed User
Longtime User
Hi @icefairy333 (& others)

This post relates to your library and project posted in the very first post of this thread (i.e post #1). The torch would not come on in that project. So, I have amended your Library code slightly and recompiled the library so that the torch can be switched on/off with the volume up/down button when the scanner is active. Hope you don't mind. The new lib files (JHSICE.jar and JHSICE.xml) are in the /files folder of the attached project. Copy them to your additional library folder. Not sure if it will work for all devices but it does work on Samsumg S4 mini.

As per your original posting - nothing else required to get this to work. Just the new xml and jar files (and of course B4A core). Manifest of the attached project already has the necessary Android permissions included.

Torch should come on by default when the scanner is activated. Then use the volume up/down buttons to toggle the torch on/off.

EDIT:

Change the following in the manifest:

AddApplicationText(<activity android:name="ice.zxing.CaptureActivity"
android:screenOrientation="landscape" android:configChanges="orientation|keyboardHidden"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:windowSoftInputMode="stateAlwaysHidden">
</activity>)

to

AddApplicationText(<activity android:name="ice.zxing.CaptureActivity"
android:screenOrientation="portrait" android:configChanges="orientation|keyboardHidden"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:windowSoftInputMode="stateAlwaysHidden">
</activity>)

Change the following at the top of the B4A project:

#Region Module Attributes
#FullScreen: False
#IncludeTitle: True
#ApplicationLabel: QR Code Scanner
#VersionCode: 1
#VersionName:
#SupportedOrientations: landscape
#CanInstallToExternalStorage: False
#End Region

to

#Region Module Attributes
#FullScreen: False
#IncludeTitle: True
#ApplicationLabel: QR Code Scanner
#VersionCode: 1
#VersionName:
#SupportedOrientations: portrait
#CanInstallToExternalStorage: False
#End Region

The view should then be correct (i.e top is top, bottom is bottom, left is left, right is right)

I have posted an upgraded version of the above project here
 

Attachments

  • IcefairyOrigWithTorch.zip
    416.5 KB · Views: 431
Last edited:

merlin2049er

Well-Known Member
Licensed User
Longtime User
I just download the library and demo last night. Seemed to work just fine. Move the begin scan to a button_click event and nothing happened. :(
 

Johan Schoeman

Expert
Licensed User
Longtime User
I just download the library and demo last night. Seemed to work just fine. Move the begin scan to a button_click event and nothing happened. :(
Can you upload the project?
 

merlin2049er

Well-Known Member
Licensed User
Longtime User
Here's the project. It's a little equipment check in/ check out app with a barcode scanner and a camera to capture a badge or business card.
Just started it.
 

Attachments

  • b4aEquipment.zip
    20.7 KB · Views: 303

Johan Schoeman

Expert
Licensed User
Longtime User
Will take a look at it in detail later today but I think you have the camera occupied with your code and then Zxing can't access the camera. If the original project that I have posted is working then your code is somewhere "interfering" with the Zxing scanner.
 

Johan Schoeman

Expert
Licensed User
Longtime User
Will take a look at it in detail later today but I think you have the camera occupied with your code and then Zxing can't access the camera. If the original project that I have posted is working then your code is somewhere "interfering" with the Zxing scanner.
Definitely got something to do with the way that you handle the camera within your code. If I comment out this:
Sub Activity_Resume
' InitializeCamera
End Sub

the scanner starts perfectly.
 
Last edited:

merlin2049er

Well-Known Member
Licensed User
Longtime User
Ok, I believe I need to separate the camera and barcode scanner into their own activities.
 

GaNdAlF89

Active Member
Licensed User
Longtime User
Sorry to hear that - not sure if it would work on that ver. Manifest text is below

B4X:
AddApplicationText(<activity android:name="ice.zxing.CaptureActivity"
            android:screenOrientation="portrait" android:configChanges="orientation|keyboardHidden"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
            android:windowSoftInputMode="stateAlwaysHidden">
        </activity>)

and the code for calling it as below - I think that the cancelled event is extra to the original but that shouldn't cause the black screen:
B4X:
' Event handler for button presses, passed variable include the in/out status
Sub DoEvent(intEventTypeNo As Int)
    ' Start scanning for barcodes
    objB4AZXing.useFrontCam = True
    objB4AZXing.isportrait=True
    objB4AZXing.endAt=DateTime.Now + (Common.SecondsToScanForBarcode * 1000)
    objB4AZXing.BeginScan("objbarcodescanning")
End Sub

' Event handler for barcodes being found
Sub objbarcodescanning_barcodefound(strFormatName As String,strBarCode As String)

End Sub

' Procedure to stop the barcode scanner
Sub objbarcodescanning_cancelled(timeout As Boolean)

End Sub
Thanks for library, I use this code but there is an error when I press on the back key:
B4X:
java.lang.NoSuchMethodError: anywheresoftware.b4a.BA.Log
What can I do? Thanks
 

Johan Schoeman

Expert
Licensed User
Longtime User

M.LAZ

Active Member
Licensed User
Longtime User
Hi @icefairy333 & every body here ..
post #127
i got this error when the capture done :
An Error has occured in Sub:
java.lang.NullPointerException Continue?
Thank you So much.
 
Last edited:
Top