B4A Library MaterialBarcodeScanner (Uses Google Mobile Vision API)

This is a wrap for this github project.

Easy to use barcode reader for your Android Project (Uses Google Mobile Vision API)
  • Integrate in a few minutes
  • Quick and simple api
  • No external apps required
  • Uses Google Mobile Vision API (fast scanning, local)
  • Automatically parses QR Codes, Data Matrix, PDF-417, and Aztec values
  • Supports 1D barcodes: EAN-13, EAN-8, UPC-A, UPC-E, Code-39, Code-93, Code-128, ITF, Codabar
  • Supports 2D barcodes: QR Code, Data Matrix, PDF-417, Aztec

MaterialBarcodeScanner
Author:
DonManfred (wrapper)
Version: 1
  • BarcodeScanner
    Methods:
    • Initialize (EventName As String)
    • IsInitialized As Boolean
    • startScan
      Start a scan for a barcode

      This opens a new activity with the parameters provided by the MaterialBarcodeScannerBuilder
  • BarcodeScannerBuilder
    Events:
    • onResult (barcode As String)
    Methods:
    • BleepEnabled (enabled As Boolean) As MaterialBarcodeScannerBuilderWrapper
      Enables or disables a bleep sound whenever a barcode is scanned
    • CameraFacing (cameraFacing As Int) As MaterialBarcodeScannerBuilderWrapper
      Either CameraSource.CAMERA_FACING_FRONT or CameraSource.CAMERA_FACING_BACK
      cameraFacing:
    • EnableAutoFocus (enabled As Boolean) As MaterialBarcodeScannerBuilderWrapper
      Enables or disables auto focusing on the camera
    • FlashLightEnabledByDefault As MaterialBarcodeScannerBuilderWrapper
      Shows a text message at the top of the barcode scanner
    • Initialize (EventName As String) As MaterialBarcodeScannerBuilderWrapper
    • IsInitialized As Boolean
    • Text (text As String) As MaterialBarcodeScannerBuilderWrapper
      Shows a text message at the top of the barcode scanner
    • TrackerColor (color As Int) As MaterialBarcodeScannerBuilderWrapper
      Sets the tracker color used by the barcode scanner, By default this is Material Red 500 (#F44336).
      color:
    • build As MaterialBarcodeScanner
      Build a ready to use MaterialBarcodeScanner
      Return type: @return:A ready to use MaterialBarcodeScanner
    • withBackfacingCamera As MaterialBarcodeScannerBuilderWrapper
      Makes the barcode scanner use the camera facing back
    • withFrontfacingCamera As MaterialBarcodeScannerBuilderWrapper
      Makes the barcode scanner use camera facing front

ATTENTION:
- You need to have google-play-services.jar in your additional libs folder
- You need to have android-support-v4.jar in your additional libs folder
- You need to have android-support-v7-appcompat..jar in your additional ibs folder. Especially the app must be prepared to use AppCompat. So follow the apcmpat tutorial.

I´ve used Example1 of the AppCompat-Tutorials and used the Button in the layout to trigger a Barcodescan

See it in action
 

Attachments

  • MaterialBarcodeEx.zip
    34.6 KB · Views: 1,049
  • MaterialBarcodelibfiles1.0.0.zip
    84.1 KB · Views: 991
  • MaterialBarcodeScannerV1.5.zip
    88.2 KB · Views: 845
Last edited:

DonManfred

Expert
Licensed User
Longtime User
You are a Barcode Master!
lol... That said from the REAL Barcode Master! :D

But you told me to write this wrap as you have seen enough barcodes for 2016. so, here it is :D
 

M6SOFT

Member
Licensed User
Longtime User
Hi,
This is great lib. I would like use it to read large aztec codes, but in this case vision api have problems. As i see (red tracker signs) probably algorithms trying read it as 1D code. Is it possible set this properties: "public BarcodeDetector.Builder setBarcodeFormats (int format)" to inform algorithm which barcode detector should recognize?
 

DonManfred

Expert
Licensed User
Longtime User
that may be. But the lib i wrapped is using the google api. The lib does not use a BarrcodeDetector.Builder. It has it´s own implementation. The MaterialBarcodeScannerBuilder. And that´s what i have wrapped. See the source here: https://github.com/EdwardvanRaak/MaterialBarcodeScanner
 

DonManfred

Expert
Licensed User
Longtime User
B4X:
mBarcodeDetector = new BarcodeDetector.Builder(mActivity).build();
that´s all of the google builder the lib is using

Edit: but this can be extended i think... trying to add setBarcodeFormat works in eclipse. So the method is IN the googles builder...

will investigate
 

DonManfred

Expert
Licensed User
Longtime User
Edit: but this can be extended i think... trying to add setBarcodeFormat works in eclipse. So the method is IN the googles builder...

Please try this version. I added a BarcodeFormat(int) to the builder
 

Attachments

  • MaterialBarcodeV1.0.1.zip
    86.1 KB · Views: 528

M6SOFT

Member
Licensed User
Longtime User
You're super fast! Unfortunately this not help in recognizing but many many thanks for Your effort with this and all other libs.

PS I send small donation. Thanks!
 

Johan Schoeman

Expert
Licensed User
Longtime User
Hi Manfred

Trying to get the scanner to work:
1. Followed this thread by @corwin42 to set up your scanner for AppCompat
2. Have followed this answer by @Erel else it takes a very long time to compile (and sometimes it would not compile at all but crashes with an out of memory error)
3. Have set up the paths etc to the additional resources in the B4A project as follows:
B4X:
#AdditionalRes: ..\resource
#AdditionalRes: ..\ResourceBarcode

#AdditionalRes: C:\Users\----------2\Documents\Basic 4 Android\JOHAN APPS\JHS LIBS\resource\b4a_appcompat, de.amberhome.objects.appcompat
#AdditionalRes: C:\ANDRIOD_SDK_TOOLS\extras\android\support\v7\appcompat\res, android.support.v7.appcompat
#AdditionalRes: C:\ANDRIOD_SDK_TOOLS\extras\google\google_play_services\libproject\google-play-services_lib\res, com.google.android.gms

'#ExcludeClasses: .games, .drive, .ads, .fitness, .wearable, .measurement, .cast, .auth, .nearby
'#ExcludeClasses: .tagmanager, .analytics, .wallet, .plus, .gcm, .maps, .panorama

'#Extends: android.support.v7.app.ActionBarActivity
#Extends: android.support.v7.app.AppCompatActivity

So, I get this:
1.png



The project starts and I can click on the Checkbox, RadioButton, Spinner (days of week), and the menu. All working OK. But when I click on the button to start the scanner the project crashes (ClassCastException):

B4X:
** Activity (main) Pause, UserClosed = true **
** Activity (main) Create, isFirst = false **
** Activity (main) Resume **
Spinner1 ItemClick event fired
Button1 Click event fired
EventBus.postSticky
Create intent
startActivity
** Activity (main) Pause, UserClosed = false **
onCreate
onMaterialBarcodeScanner
startCameraSource
new SoundPoolPlayer
start check isGooglePlayServicesAvailable
isGooglePlayServicesAvailable 0
success = 0
setupLayout
setupButtons
java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to com.android.internal.widget.ActionBarOverlayLayout$LayoutParams
    at com.android.internal.widget.ActionBarOverlayLayout.applyInsets(ActionBarOverlayLayout.java:204)
    at com.android.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:402)
    at android.view.View.measure(View.java:17331)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5376)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
    at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2548)
    at android.view.View.measure(View.java:17331)
    at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2279)
    at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1393)
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1592)
    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1251)
    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6540)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:813)
    at android.view.Choreographer.doCallbacks(Choreographer.java:613)
    at android.view.Choreographer.doFrame(Choreographer.java:583)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:799)
    at android.os.Handler.handleCallback(Handler.java:733)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:146)
    at android.app.ActivityThread.main(ActivityThread.java:5593)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
    at dalvik.system.NativeStart.main(Native Method)

Any idea what is the solution for this error?
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
Any idea what is the solution for this error?
Not as yet. Maybe you need to post your manifest. There are changes in the example i provided to setup the google play service correctly.

SetApplicationAttribute(android:theme, "@style/MyAppTheme")
AddApplicationText(<meta-data
android:name="com.google.android.gms.version"
android:value="@Integer/google_play_services_version" />
<meta-data
android:name="com.google.android.gms.vision.DEPENDENCIES"
android:value="barcode" />)
AddApplicationText(<activity
android:theme="@style/AppTheme.NoActionBar"
android:name="com.edwardvanraak.materialbarcodescanner.MaterialBarcodeScannerActivity"
android:label="@string/library_name" >
</activity>)
AddPermission(android.permission.CAMERA) ' Required to be able to access the camera device.
 

Johan Schoeman

Expert
Licensed User
Longtime User
Maybe you need to post your manifest
Here is the Manifest:
B4X:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: http://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="21"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
SetApplicationAttribute(android:label, "$LABEL$")

'End of default text.

SetApplicationAttribute(android:theme, "@style/MyAppTheme")
AddApplicationText(<meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
        <meta-data
            android:name="com.google.android.gms.vision.DEPENDENCIES"
            android:value="barcode" />)
AddApplicationText(<activity
            android:theme="@style/AppTheme.NoActionBar"
            android:name="com.edwardvanraak.materialbarcodescanner.MaterialBarcodeScannerActivity"
            android:label="@string/library_name" >
        </activity>)
AddPermission(android.permission.CAMERA) ' Required to be able to access the camera device.
 

Johan Schoeman

Expert
Licensed User
Longtime User
OK - I've got it working. I have changed ....\ResourceBarcode\values\styles.xml from
B4X:
<resources>

    <!-- Base application theme. -->
     <style name="AppTheme" parent="AppTheme.NoActionBar"/>
    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

</resources>

....to....

B4X:
<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat"/>

    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

</resources>

2.png
 

Wolli013

Well-Known Member
Licensed User
Longtime User
Work by Samsung Galaxy s6 perfect - thank you DonManfred ! :D:D:D:D:D

Not Work by Samsung Galaxy s3 - App stopped by scan :mad:
Not Work by Samsung Galaxy Tab4 - App stopped by scan :mad:

Sorry for my english
 

Johan Schoeman

Expert
Licensed User
Longtime User
Work by Samsung Galaxy s6 perfect - thank you DonManfred ! :D:D:D:D:D

Not Work by Samsung Galaxy s3 - App stopped by scan :mad:
Not Work by Samsung Galaxy Tab4 - App stopped by scan :mad:

Sorry for my english
Replace the code in the B4A project's \ResourceBarcode\values\styles.xml file with this code and see if it sorts out the problem:

B4X:
<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat"/>

    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

</resources>
 
Top