Android Example [B4X] [B4XPages] Barcode Reader

Status
Not open for further replies.
1595341203504.png
i_view64_HkncBfNNKe.png


B4A + B4i barcode reader.

Don't miss:

- #PlistExtra in B4i.
- Manifest code + #AdditionalJar in B4A

Depends on BCToast: https://www.b4x.com/android/forum/t...platform-custom-toast-message.111046/#content
(BCToast will be an internal library in the near future)

While the camera related code is platform specific, the main program logic can still be shared. In this case there isn't too much logic but in real usage the benefit of implementing it like this will be higher.

Requires Android 5+.

Supported formats:
B4A - https://developers.google.com/andro...d/gms/vision/barcode/Barcode#constant-summary
B4i - TYPE_QR, TYPE_UPCE, TYPE_39, TYPE_39Mod43, TYPE_EAN13, TYPE_EAN8, TYPE_93, TYPE_128, TYPE_PDF417

Updates:

B4i iBarcode v1.21 - Adds support for setting the scan window: https://www.b4x.com/android/forum/threads/ibarcode-library.47354/post-836360
 

Attachments

  • BarcodeReader.zip
    183.5 KB · Views: 1,369
Last edited:

Mark Thorndyke

Member
Licensed User
Longtime User
Liking this and quick change getting all bar-codes required.
Surprised you've not used the new Toast in the CameraExClass class ;)
 

imbault

Well-Known Member
Licensed User
Longtime User
Thanks you @Erel for this very interesting project :

I'd like to add to switch button to disable/enable barecode capture while continuing previewing but how to stop BC capturing and resuming BC capturing in the code ?

Thanks a lot

Patrick
 

dws

Member
Licensed User
Longtime User
After version 10.2 Error when press then start button. What is wrong ?
In version 9.80 working fine.


b4xmainpage$ResumableSub_StartCameraresume (java line: 258)
java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/core/content/ContextCompat;
at anywheresoftware.b4a.objects.RuntimePermissions.Check(RuntimePermissions.java:73)
at anywheresoftware.b4a.objects.RuntimePermissions.CheckAndRequest(RuntimePermissions.java:97)
at b4a.cambarcodereader.b4xmainpage$ResumableSub_StartCamera.resume(b4xmainpage.java:258)
at b4a.cambarcodereader.b4xmainpage._startcamera(b4xmainpage.java:235)
at b4a.cambarcodereader.b4xmainpage._btnstartstop_click(b4xmainpage.java:76)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:7161)
at android.view.View.performClickInternal(View.java:7138)
at android.view.View.access$3500(View.java:811)
at android.view.View$PerformClick.run(View.java:27419)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:224)
at android.app.ActivityThread.main(ActivityThread.java:7548)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
Caused by: java.lang.ClassNotFoundException: androidx.core.content.ContextCompat
... 20 more
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
 

josejad

Expert
Licensed User
Longtime User
Have you just installed 10.2? Or have you followed the instructions? Have you updated the SDK as described?
 

LucaMs

Expert
Licensed User
Longtime User
I tried it on some barcodes without success.

I had to replace:
B4X:
CreateDetector (Array("CODE_128", "CODE_93", "QR_CODE"))

with:
B4X:
CreateDetector (Array("AZTEC", "CODE_128", "CODE_39", "CODE_93", "CODABAR", "DATA_MATRIX", "EAN_13", "EAN_8", "ITF", "PDF417", "QR_CODE", "UPC_A", "UPC_E"))

I don't know if it actually recognizes all those types but the ones I tried previously are now recognized.
B4A ONLY
 
Last edited:

Xfood

Expert
Licensed User
is there any way to enable pointer while reading code?
 

Attachments

  • lettore-codici-a-barre.jpg
    lettore-codici-a-barre.jpg
    18.8 KB · Views: 484

amorosik

Expert
Licensed User
In one-dimensional codes, it only reads them if they are arranged horizontally or vertically
It is a limit to know otherwise you risk not being able to read even the barcodes that the program would be able to decode
This seems a bit strange to me because, graphically speaking, even the two-dimensional ones are actually sequences of one-dimensional codes placed one on top of the other.
And if he reads the qr-code at 45 degrees with respect to the lens, it means that he has the ability to read diagonally.
 

pacpinto

Member
Licensed User
In one-dimensional codes, it only reads them if they are arranged horizontally or vertically
It is a limit to know otherwise you risk not being able to read even the barcodes that the program would be able to decode
This seems a bit strange to me because, graphically speaking, even the two-dimensional ones are actually sequences of one-dimensional codes placed one on top of the other.
And if he reads the qr-code at 45 degrees with respect to the lens, it means that he has the ability to read diagonally.
Hi, I have exactly the same issue. Any ideas would be very welcome. I have a use case where this makes a difference. Thank you in advance.
 

Pepebis

Member
Licensed User
Longtime User
Hello.
An example is working. But when I'm trying to use it my B4x pages I have a problem.
B4X:
java.lang.reflect.InvocationTargetException
pointing on line with line
B4X:
builder.InitializeNewInstance("com/google/android/gms/vision/barcode/BarcodeDetector.Builder".Replace("/", "."), Array(ctxt))
I have change manifest, i don't understand if I'm doing it correctly because after changes and trying to open the app manifest going back to previous state. I'm adding this line inside manifest.

B4X:
<meta-data
            android:name="com.google.android.gms.vision.DEPENDENCIES"
            android:value="barcode,face" />

Also as per instruction can't find jar file .

Don't miss:

- #PlistExtra in B4i.
- Manifest code + #AdditionalJar in B4A
 

Pepebis

Member
Licensed User
Longtime User
something is wrong. before opening b4a I'm changing this line adding that line with meta ( I'm using notepad to modify this file ) then after running app manifest removing that line which i added before. The manifest file which I'm changing is in b4->objects->AndroidManifest
 

vmag

Active Member
This is probably the best example for scanning barcodes! A minimum of code, and if you have the latest version of b4a, then no dancing with a tambourine is required. Thank you to the developers!
 
Status
Not open for further replies.
Top