B4A Library Another B4A Barcode Scanner - based on Android Vision

Johan Schoeman

Expert
Licensed User
Sure you will figure it out - check the B4A log when scanning a barcode

Copy the .jar and .xml files to your B4A additional libs folder.

B4A code:

B4X:
#Region  Project Attributes
    #ApplicationLabel: jhsScanOnly
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: portrait
    #CanInstallToExternalStorage: False
'    #MultiDex: True

#End Region


#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

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.

    Private bs1 As BillScanner
    Private Button1 As Button

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("main")
    
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)
    
      bs1.stopScanning
      
End Sub

Sub bs1_scan_value(val As String, rawbyte() As Byte, barcodetype As Int)
    
    Log("Value = " & val)
    Log("type = " & barcodetype)
    Log(" ")
    
End Sub

Sub Button1_Click
    
    bs1.startScanning
    
End Sub
I guess you know how to make this "RuntimePermissions" compliant.

Take note of this in the B4A Manifest file:

B4X:
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" />)
This is the scanner that I am using here.....


Zxing does not work - this scanner (based on Android Vision) does the job.

Enjoy.....;)
 

Attachments

Zlgo

Member
Hi Johan
I just try your demo but in compiling receive massage : " Maven artifact not found: androidx.annotation/annotation-experimental". B4A version 10.2 ,Java version 8.
 

Zlgo

Member
Thanks, this problem is solved, but now compiler report long list of errors like:

Java Version: 8
Parsing code. (0.00s)
Building folders structure. (0.01s)
Compiling code. (0.02s)
Compiling layouts code. (0.00s)
Organizing libraries. (4.60s)
(AndroidX SDK)
Generating R file. (2.02s)
Compiling debugger engine code. (0.81s)
Compiling generated Java code. (2.13s)
Convert byte code - optimized dex. Error
trouble writing output: Too many field references to fit in one dex file: 74723; max is 65536.
You may try using multi-dex. If multi-dex is enabled then the list of classes for the main dex list is too large.
References by package:
2 android.accounts
27 android.app
1 android.content
33 android.content.pm
17 android.content.res
3 android.database
111 android.graphics
4 android.hardware
2 android.media
1 android.media.browse
2 android.net
21 android.os
3 android.print
6 android.support.v4.app
210 android.support.v4.media
380 android.support.v4.media.session
12 android.support.v4.os
1 android.system
16 android.text
1 android.text.util
2 android.transition
15 android.util
29 android.view
15 android.view.accessibility
3 android.view.inputmethod
1 android.view.textclassifier
19 android.widget
29 androidx.activity
22 androidx.annotation
3 androidx.annotation.experimental
9 androidx.annotation.experimental.lint
3682 androidx.appcompat
392 androidx.appcompat.app
 

Johan Schoeman

Expert
Licensed User
Thanks, this problem is solved, but now compiler report long list of errors like:

Java Version: 8
Parsing code. (0.00s)
Building folders structure. (0.01s)
Compiling code. (0.02s)
Compiling layouts code. (0.00s)
Organizing libraries. (4.60s)
(AndroidX SDK)
Generating R file. (2.02s)
Compiling debugger engine code. (0.81s)
Compiling generated Java code. (2.13s)
Convert byte code - optimized dex. Error
trouble writing output: Too many field references to fit in one dex file: 74723; max is 65536.
You may try using multi-dex. If multi-dex is enabled then the list of classes for the main dex list is too large.
References by package:
2 android.accounts
27 android.app
1 android.content
33 android.content.pm
17 android.content.res
3 android.database
111 android.graphics
4 android.hardware
2 android.media
1 android.media.browse
2 android.net
21 android.os
3 android.print
6 android.support.v4.app
210 android.support.v4.media
380 android.support.v4.media.session
12 android.support.v4.os
1 android.system
16 android.text
1 android.text.util
2 android.transition
15 android.util
29 android.view
15 android.view.accessibility
3 android.view.inputmethod
1 android.view.textclassifier
19 android.widget
29 androidx.activity
22 androidx.annotation
3 androidx.annotation.experimental
9 androidx.annotation.experimental.lint
3682 androidx.appcompat
392 androidx.appcompat.app
Look for:
# Mulitdex: True
 

Zlgo

Member
Look for:
# Mulitdex: True
Bingo, this option was marked ('), but also need this Runtimepermision to add in code (otherwise app crash)
B4X:
rp.CheckAndRequest(rp.PERMISSION_CAMERA)
    Wait For Activity_PermissionResult (Permission As String, ResultPermission As Boolean)
Now it works pretty good, but is there option to choose wich barcode only to read?
 
Top