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:

Sergio Haurat

Active Member
Licensed User
Longtime User
My English = Google translator, sorry
It is possible that the rectangle where the scan is done, it will expand more?
 

Sergio Haurat

Active Member
Licensed User
Longtime User
In Manifest file try:
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>)
 

somed3v3loper

Well-Known Member
Licensed User
Longtime User
In Manifest file try:
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>)
Thanks but the screen is still landscape. I mean the viewfinder or whatever its name is .
I have to turn phone to landscape so I can scan codes
 

joneden

Active Member
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
 

Attachments

  • b4aZXing 1.2.zip
    250.8 KB · Views: 440

joneden

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
 

LucaMs

Expert
Licensed User
Longtime User
I was wrong.

I had forgotten to change the Manifest File.

It works great!

We should erect a monument dedicated to you!

Thank you very much, great job, Jon

(endAt is the maximum time that is allowed to perform the scan?)
 
Last edited:

joneden

Active Member
Licensed User
Longtime User
:) Good to hear that it works :)

Yes, I have it for a Time and Attendance app amongst others and needed a way to have a time out on it so that did the trick. Watch out with the sub naming as I found that case plays an important part on them.

Enjoy
 

eduardo74

Member
Licensed User
Longtime User
I have problem with Galaxy Tab 3 7", no autofocus... any idea
Galaxy S3 and Galaxy S4 working very good
 

jruiz1998

Member
Licensed User
Longtime User
Jon,
Very good.

Just one question,
It does not recognize "Common". It says "Undeclared Variable..."

Thanks
JRuiz
 

dibb3386

Member
Licensed User
Longtime User
Hi, Ive got the camera running on a panel and this running on a transparent panel ontop of this, however I get an error java.lang.ClassCastException: anywheresoftware.b4a.BALayout cannot be cast to android.view.SurfaceView.

Why has this happened? Can i not use zxinglib in my own panel? Idea was to have the camera running and the zxinglib to scan so you can see what you scanning, looking in to a qr code scanner built in to my app.
Any help would be great
Thanks
 

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.
 

petronas

New Member
Licensed User
Longtime User
Hi Joneden,

May I request for the demo project using your tweaked ABZxing lib?

THanks
Petronas
 
Top