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,268
  • b4aZxingLibsrc.zip
    325.9 KB · Views: 1,942
  • b4azxing1.5.zip
    249.2 KB · Views: 2,012
Last edited:

Johan Schoeman

Expert
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.
Are you using the project in post #127 or your own project based on the project in post #127? Does the error occur with all QR Codes that you scan or only with certain QR Codes? If only certain QR Codes, can you post one of those QR Codes? If your own project, did you add/change the following to/in the manifest files of your project?

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>)

I have tested it on a number of QR Codes and it scans all without any issues.
 
Last edited:

M.LAZ

Active Member
Licensed User
Longtime User
Thanks Johan,
yes i'm using the project in post #127,this error occurred when i try to capture EAN-8 or EAN-13 barcodes, i think the problem from the parameter bts() As Byte
because when i use the other parameters (atype As String , Values As String ) there is no error and work perfectly.

B4X:
Sub myzx_result(atype As String,Values As String,bts() As Byte)

''Log("type:" & atype & " -  values:" & Values & " -  rawbytes(hex):" & bc.HexFromBytes(bts))

''Msgbox("type:" & atype & " -  values:" & Values &" -  rawbytes(hex):" & bc.HexFromBytes(bts),"result")
 
 
Msgbox("atype : " & atype  & "Values : " & Values ,"Barcode")

    ListView1.AddTwoLines(Values)
    ListView1.TwoLinesLayout.ItemHeight=70dip
    ListView1.TwoLinesLayout.SecondLabel.Height=70dip
    ListView1.TwoLinesLayout.Label.TextSize = 20
    ListView1.TwoLinesLayout.Label.TextColor = Colors.Blue
    ListView1.TwoLinesLayout.SecondLabel.TextSize = 16
 
 
End Sub

YES I ADD IT TO the manifest files.
 

mike2506

Member
Licensed User
Longtime User
I need to read a barcode EAN13 format + EAN5 as in the attached image. Can someone help me. Thank you
 

Attachments

  • EAN13_EAN5_2.png
    EAN13_EAN5_2.png
    125.8 KB · Views: 198
  • EAN13_EAN5_2.png
    EAN13_EAN5_2.png
    125.8 KB · Views: 192

Johan Schoeman

Expert
Licensed User
Longtime User

mike2506

Member
Licensed User
Longtime User
Thanks for the reply, but the barcode consists of an EAN13 code and a small distance from a code of EAN5. Italian newspapers have this dual code that locates the newspaper (EAN13) and the date of publication (EAN5). The double code should be read in a single step. In annex I reproduce an example of such code
27426-bac31ede92f241ebae15dcfa9ce44919.jpg
 

Johan Schoeman

Expert
Licensed User
Longtime User
Thanks for the reply, but the barcode consists of an EAN13 code and a small distance from a code of EAN5. Italian newspapers have this dual code that locates the newspaper (EAN13) and the date of publication (EAN5). The double code should be read in a single step. In annex I reproduce an example of such code
27426-bac31ede92f241ebae15dcfa9ce44919.jpg
Seems to me as if the original ZXING project does not support EAN5
 

Johan Schoeman

Expert
Licensed User
Longtime User
Black screen of tablet Asus. It works with Samsung.
I suggest you read through this complete thread and see what changes to the manifest have sorted out similar problems. And then try those suggestions and see if it solves the problem.
 

BluSky76

Member
Licensed User
Longtime User
Thank you.
I tried various solutions, but do not work on Asus products. I have two different models asus and does not work on any of the two.
 

manuel-r

Member
Licensed User
Longtime User
Hi @All

I've a problem with the orientation of the scanning line. My app works in portrait mode. The scanning area should be part of full screen in landscape orientation. That's no problem. But the scanning line then is verticaly (red in picture) while I need horizontaly (blue in attached picture).

Can anybody help me?

B4X:
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
    Dim objScanRect As Rect
    Dim objPreRect As Rect
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")
    objScanRect.Initialize(5%x,0,30%y,100%x)
    objPreRect.Initialize(5%x,0,30%y,100%x)
    zx.preRect = objPreRect
    zx.scanRect = objScanRect
    zx.BeginScan("myzx")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub myzx_result(atype As String,Values As String)
   Log("type:"&atype&"values:"&Values)
   Msgbox("type:"&atype&"values:"&Values,"result")
End Sub
 

Attachments

  • Codescanner b4a.PNG
    Codescanner b4a.PNG
    128.2 KB · Views: 214

manuel-r

Member
Licensed User
Longtime User
Bei dem Vornamen vermute ich mal du sprichst deutsch ;-)
Das mit dem Manifest-File habe ich schon gemacht. Allerdings dreht dann der Bildschirm auf Landscape. Ich will den ja in Portrait behalten, aber den Scanbereich auf ein waagerechtes Rechteck festlegen.
Zwischenzeitlich habe ich aber deinen Thread unter https://www.b4x.com/android/forum/t...y-johan-schoeman-qr-codes-and-barcodes.49084/ gefunden und die Beispiele dort angetestet. Die machen genau das was ich will. Kann das an den Modifikationen liegen die du in die Lib eingebaut hast?

Gruß
Manuel
 

manuel-r

Member
Licensed User
Longtime User
Hi Johann
You wrote me that you don't understand german as good as I thougt. So I try to repeat my post in english.

I've allready edited the manifest file. But with no good result.
If I do so the Display switches 90° against the position of the smartphone. My intent is to hold the mobile in portrait and configure the scaning area to an rectangle that looks like 90% width and 30% height.
If I switch the manifest to "portrait" I get an image on the mobile that looks like picture "manifest portrait". You see, that it is turned left because my monitor still standing at the table ;-)
If I change to landscape in the manifest file the orientation is as expected (picture "manifest landscape"). The scanning aera is correct too. But the scanning line is verticaly instead of being horizontaly.

Meanwhile I found your post in https://www.b4x.com/android/forum/t...y-johan-schoeman-qr-codes-and-barcodes.49084/ so I will try to do it with your modified library.
 

Attachments

  • manifest landscape.png
    manifest landscape.png
    123 KB · Views: 202
  • manifest portrait.png
    manifest portrait.png
    185.6 KB · Views: 199

Johan Schoeman

Expert
Licensed User
Longtime User
Hi Johann
You wrote me that you don't understand german as good as I thougt. So I try to repeat my post in english.

I've allready edited the manifest file. But with no good result.
If I do so the Display switches 90° against the position of the smartphone. My intent is to hold the mobile in portrait and configure the scaning area to an rectangle that looks like 90% width and 30% height.
If I switch the manifest to "portrait" I get an image on the mobile that looks like picture "manifest portrait". You see, that it is turned left because my monitor still standing at the table ;-)
If I change to landscape in the manifest file the orientation is as expected (picture "manifest landscape"). The scanning aera is correct too. But the scanning line is verticaly instead of being horizontaly.

Meanwhile I found your post in https://www.b4x.com/android/forum/t...y-johan-schoeman-qr-codes-and-barcodes.49084/ so I will try to do it with your modified library.
Use the project that I have posted here. It is set up for portrait. Make sure you copy the jar and xml that are in the /files folder of the B4A project to your additional libraries folder.

https://www.b4x.com/android/forum/t...r-codes-and-barcodes.49084/page-3#post-346040
 

GaNdAlF89

Active Member
Licensed User
Longtime User
@Johan Schoeman
Thanks for all. But if I touch the display (at any position) the app is stopped, with this exception:
B4X:
java.lang.RuntimeException: setParameters failed
   at android.hardware.Camera.native_setParameters(Native Method)
   at android.hardware.Camera.setParameters(Camera.java:1452)
   at ice.zxing.camera.CameraManager.myTorchParametersOn(CameraManager.java:205)
   at ice.zxing.CaptureActivity.onTouchEvent(CaptureActivity.java:118)
   at android.app.Activity.dispatchTouchEvent(Activity.java:2471)
   at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2061)
   at android.view.View.dispatchPointerEvent(View.java:7525)
   at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3370)
   at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3302)
   at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4394)
   at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4372)
   at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4476)
   at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:171)
   at android.os.MessageQueue.nativePollOnce(Native Method)
   at android.os.MessageQueue.next(MessageQueue.java:125)
   at android.os.Looper.loop(Looper.java:124)
   at android.app.ActivityThread.main(ActivityThread.java:4895)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:511)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
   at dalvik.system.NativeStart.main(Native Method)
What is the problem? Thanks
 

Johan Schoeman

Expert
Licensed User
Longtime User
@Johan Schoeman
Thanks for all. But if I touch the display (at any position) the app is stopped, with this exception:
B4X:
java.lang.RuntimeException: setParameters failed
   at android.hardware.Camera.native_setParameters(Native Method)
   at android.hardware.Camera.setParameters(Camera.java:1452)
   at ice.zxing.camera.CameraManager.myTorchParametersOn(CameraManager.java:205)
   at ice.zxing.CaptureActivity.onTouchEvent(CaptureActivity.java:118)
   at android.app.Activity.dispatchTouchEvent(Activity.java:2471)
   at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2061)
   at android.view.View.dispatchPointerEvent(View.java:7525)
   at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3370)
   at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3302)
   at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4394)
   at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4372)
   at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4476)
   at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:171)
   at android.os.MessageQueue.nativePollOnce(Native Method)
   at android.os.MessageQueue.next(MessageQueue.java:125)
   at android.os.Looper.loop(Looper.java:124)
   at android.app.ActivityThread.main(ActivityThread.java:4895)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:511)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
   at dalvik.system.NativeStart.main(Native Method)
What is the problem? Thanks

What is the link of the project that you are referring to?
 

Johan Schoeman

Expert
Licensed User
Longtime User
With what library files? Library files from a project in this thread or in the thread of the link that you have posted? It is working and has been tested by numerous members of the B4A forum. Maybe you are doing somerhing wrong. Some libs in that thread goes with certain lib files that was posted in that thread. Most of the postings in that thread have the lib files inside the /Files folder of the B4A project (as far as what I can remember). Make sure to copy the lib files of that project to your additional library folder.
 

jruiz1998

Member
Licensed User
Longtime User
I did that, it stops without any exception

Sub Activity_Touch (Action As Int, x As Float, y As Float)
vv.Stop
Log("Playing Touch Stopped")
zx.BeginScan("myzx") ' It begins again
End Sub
 
Top