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,412
  • b4aZxingLibsrc.zip
    325.9 KB · Views: 2,076
  • b4azxing1.5.zip
    249.2 KB · Views: 2,167
Last edited:

incendio

Well-Known Member
Licensed User
Longtime User
Able to do multiple scan in one shot without significant delay.

Calling again BeginScan caused a delay.
 

Sytek

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

Tested on a Dell Venue 8" Works just Fine with the 1.2 Version Library in both cameras
Best Regards!
 

AHilton

Active Member
Licensed User
Longtime User
Has anyone tried the Moto G with this library? Not all phones and tablets have the capability to autofocus close enough for good barcode reading or don't have a macro setting. From what I've read, the Moto G has some strange focusing but I haven't gotten my hands on one yet to test.


Got my hands on one and I'll answer my own question and say, "yes", the Moto G does work.
 

adastra

Member
Licensed User
Longtime User
i have used the library b4a Zxing but it does not scan barcode. only shows red line and yellow dot.
 

Alberto Iglesias

Well-Known Member
Licensed User
Longtime User
Hey Ice, Can you put this parameters in your library like optional?

zx.SetJpegQuality(90)
zx.SetPreviewFpsRange(30000, 30000)
zx.SetPreviewSize(640, 360)

I need this to work with GOOGLE GLASS....

I put this in CAMERAEX (from EREL) and work perfectly

Sub Camera1_Ready (Success As Boolean)

If Success Then
camEx.SetJpegQuality(90)
camEx.SetPreviewFpsRange(30000, 30000)
camEx.SetPreviewSize(640, 360)
camEx.CommitParameters
 

Douglas Farias

Expert
Licensed User
Longtime User
@icefairy333 its possible add cancel event?
when qr code reader is opned and user press back key *-*
show canceled
 

Johan Schoeman

Expert
Licensed User
Longtime User
Hi All,

Attached is my tweak to this lib, it was written for my use cutting out parts that I didn't need so it may work for you and it may not. This one allow portrait use, full screen scanning, timeout after x seconds etc. Oh and you can select front or back cameras so it works on the Nexus.

It's unsupported and included to bail you out if you have no other option. Icefairy I can supply you with the altered source code if you want it although it's ages since I worked on this.

Hope it helps someone!

Cheers

Jon


Hi Jon

This is brilliant! Between you and @icefairy333 - well done! It works perfectly!
 

Dr. Guaranexx

New Member
Licensed User
Longtime User
This library is a great addition, and has been very useful. I am currently using this library to read a QR code on employee ID cards using the front-facing camera, and it is working well for the most part. However, I am running into an issue where the scanner cannot read the QR codes very well in darker environments. I believe that if the frame surrounding the scanning area were turned into a lighter color, the tablet screen would emit enough light to help illuminate the QR code better. Is there a way that the setting for the surrounding frame could be modified through B4A?

I took a quick look through the b4aZxing library source files, and it appears that this could be changed within the ViewfinderView object constructor method in the src\ice\zxing\view\ViewfinderView.java file in the following line of code:

maskColor=Color.argb(96, 0, 0, 0);

Unfortunately, I am far from being a Java expert, and have been unsuccessful in regenerating the Jar file. Any help would be greatly appreciated!

Edit:
It looks like only the source to v1.2 of the library is provided. Since the ability to use the front-facing camera was added in v1.5, any modifications made to the library will need to be made to v1.5 :( Hopefully icefairy will have some time to upload the source code to v1.5 soon.
 
Last edited:

AHilton

Active Member
Licensed User
Longtime User
Icefairy333,

I'd like to talk with you about this library. If you could contact me when you have just a moment, I'd appreciate it. Thanks.
 

antyca

Member
Licensed User
Longtime User
Hi icefairy333

how to activate the camera flash to read a code correctly if the light level is low?

Thank
 
Top