B4A Library android-quick-response-code - another 1D & 2D barcode scanner

It is an absolute bare minimum wrap for this Github project - just enough to start the scanner. I leave the rest up to whoever wants to add (a lot of) functionality to it such as:
1. Change the laser color
2. Change the text color
3. Change the background color
4. Pass the scanned result back to B4A - you need to do it in public void ResultArrived(int arg0, Intent data) { of the wrapper (aQrcWrapper.java) but will have to create the intent in CaptureActivity.java
5. etc, etc, etc

Above reasonably easy to do - so I leave it to those that wants to complete the wrapper.

Posting the following:
1.The B4A project
2. The B4A library files - copy them to your additional library folder
3. a zipped file containing core-3.2.2-20150819.125554-1.jar - copy it to your additional library folder
4. The Java Code (src folder). You need to create a folder called libs on the same folder level as the src folder and copy core-3.2.2-20150819.125554-1.jar into this folder in order to compile the Java code with SLC or with Eclipse.

1.png



2.png


A nice challenge - enjoy!
 

Attachments

  • AndroidQuickResponseCodeLibFiles.zip
    101.9 KB · Views: 539
  • b4aAndroidQuickResponseCode.zip
    135.8 KB · Views: 509
  • core-3.2.2-20150819.125554-1.zip
    484 KB · Views: 522
  • TheJavaCode.zip
    109.1 KB · Views: 461

Johan Schoeman

Expert
Licensed User
Longtime User
Posting an update - have added some code to the wrapper and the original project:
1. Set the laser color
2. Set the mask color
3. set the status text, text size, and text color
4. set the "possible result points" color and size
5. set the view finder frame color
6. choose between front and back camera (note that I have not added code to test for front and back cameras - you can for eg use THIS to test for front and back camera being available on a device)

It will return the bitmap of the scanned barcode, the barcode type (eg QR_CODE), and the barcode content/data to the B4A project.

It should scan the following 1D & 2D codes:

UPC_A
UPC_E
EAN_13
EAN_8
RSS_14
CODE_39
CODE_93
CODE_128
ITF
CODABAR
QR_CODE
DATA_MATRIX
PDF_417
AZTEC
MAXICODE
RSS_EXPANDED
UPC_EAN_EXTENSION


4.png


5.png


Main Activity:
B4X:
#Region  Project Attributes
    #ApplicationLabel: AndroidQuickResponseCode
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: landscape
    #CanInstallToExternalStorage: False
#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.

    'Dim nativeMe As JavaObject
    Dim HasAnyActivityPaused As Boolean = False


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 Button1 As Button

    Dim settings(3) As Boolean

    Private ImageView1 As ImageView
    Private Label1 As Label
    Private Label2 As Label
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")
    ImageView1.Visible = False
    Label1.Visible = False
    Label2.Visible = False

End Sub

Sub Activity_Resume

    HasAnyActivityPaused = False

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Button1_Click

  CallSubDelayed2(Main_Scanner, "StartScan", settings)

End Sub

Sub GetResult(retval As List)                             'This is called by activity Main_Scanner (with the result of the scan)

    HasAnyActivityPaused = False
    ImageView1.Bitmap = retval.Get(0)                     'the bitmap of the scanned barcode
    Log("back in main " & retval.Get(1))                  'the TYPE of barcode that was scanned
    Log("back in main " & retval.Get(2))                  'the data that is contained in the barcode
    ImageView1.Visible = True
    Label1.Text = "Type : " & retval.Get(1)
    Label1.Visible = True
    Label2.text = "Data : " & retval.Get(2)
    Label2.Visible = True

End Sub

Main_Scanner activity:
B4X:
#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.

        Dim myscan As AndroidQuickResponseCode
   

End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:

        If Main.HasAnyActivityPaused = False Then
           Activity.LoadLayout("main2")
   
          myscan.Initialize("myscan")

        Else
            Activity.Finish
        End If

End Sub

Sub Activity_Resume


End Sub

Sub Activity_Pause (UserClosed As Boolean)

Main.HasAnyActivityPaused = True

End Sub

Sub StartScan(settings() As Boolean)

    'All of the below are passed to aQrcWrapper.java (setters) and then to various other classes - see comments below
    myscan.StatusViewText = "Wrapped by Johan Schoeman"               'it is used in CaptureActivity.java
    myscan.StatusViewTextSize = 20                                    'it is used in CaptureActivity.java
    myscan.StatusViewTextColor = Colors.Magenta                       'it is used in CaptureActivity.java

    myscan.LaserColor = Colors.Yellow                                 'it is used in ViewfinderView.java
    myscan.PossibleResultPointColor = Colors.Red                      'it is used in ViewfinderView.java
    myscan.PossibleResultPointSize = 8                                'it is used in ViewfinderView.java
    myscan.ViewfinderFrameColor = Colors.White                        'it is used in ViewfinderView.java

    myscan.MaskColor = 0x88000088                                     'it is used in ViewfinderView.java

    myscan.CameraToUse = myscan.CAMERA_BACK                           'it is used in CameraManager.java

    myscan.beginScan

End Sub

Sub myscan_scan_result(image As Object, btype As String, bcontent As String)             'this event is raised by the library when a scan occured
                      
    Dim retval As List                                                                    'use a list to pass the info back to activity Main
    retval.Initialize                                                                      'initialize the list
    retval.Add(image)                                                                     'add the bitmap image to the list
    retval.Add(btype)                                                                     'add the barcode type to the list
    retval.Add(bcontent)                                                                  'add the barcode data to the list

    CallSubDelayed2(Main, "GetResult", retval)                                            'pass the scanned result back to the Main activity.


    Activity.Finish                                                                       'kill this activity so that the Main activity is displayed

End Sub

Library:
AndroidQuickResponseCode
Author:
Github: Justin Wetherell, Wrapped by: Johan Schoeman
Version: 1
  • AndroidQuickResponseCode
    Events:
    • scan_result (image As Object, barcodetype As String, barcodecontent As String)
    Fields:
    • CAMERA_BACK As Int
    • CAMERA_FRONT As Int
    Methods:
    • BeginScan
      Called when a view has been clicked.
      v: The view that was clicked.
    • Initialize (paramString As String)
    • IsInitialized As Boolean
    Permissions:
    • android.hardware.camera
    • android.hardware.camera.autofocus
    • android.permission.CAMERA
    • android.permission.FLASHLIGHT
    • android.permission.VIBRATE
    • android.permission.WRITE_EXTERNAL_STORAGE
    Properties:
    • CameraToUse As Int [write only]
    • LaserColor As Int [write only]
    • MaskColor As Int [write only]
    • PossibleResultPointColor As Int [write only]
    • PossibleResultPointSize As Int [write only]
    • StatusViewText As String [write only]
    • StatusViewTextColor As Int [write only]
    • StatusViewTextSize As Int [write only]
    • ViewfinderFrameColor As Int [write only]

Posting:
1. Updated B4A project
2. The Java Code (only the src folder - see post #1 for the libs folder)
3. Updated B4A library files (see post #1 for core-3.2.2-20150819.125554-1.jar)

Take note of the B4A project's manifest file....
 

Attachments

  • TheJavaCode.zip
    110.2 KB · Views: 419
  • AndroidQuickResponseCodeLibFiles.zip
    103.5 KB · Views: 441
  • b4aAndroidQuickResponseCode.zip
    136.8 KB · Views: 431
Last edited:

Johan Schoeman

Expert
Licensed User
Longtime User
Nice wrap!

The view is upside down though. Anything I can do about it?

View attachment 44697
Turn your device 180 degrees - and then just ignore the writing that is upside down....:)
Jokes aside - what device are you running it on?
 

Johan Schoeman

Expert
Licensed User
Longtime User
On Nexus 5X, API 23 it's rotated
On Huawei Media Pad 7, API 15 it's correct
Please try with the attached lib files and see if it fixes the issue that you have with the Nexus - nothing changed as far as the B4A code is concerned
 

Attachments

  • AndroidQuickResponseCodeLibFilesNexus.zip
    104.8 KB · Views: 393

mojako

Member
Licensed User
I got bad experience with this libs. when I callsubdelayed2, the subs Activity_Create and StartScan was called in Main_Scanner activity file. but after myscan.beginScan then end Sub in Sub StartScan, the process directly back to sub Activity_Resume in caller activity not in Main_Scanner activity.
 

Johan Schoeman

Expert
Licensed User
Longtime User
I got bad experience with this libs. when I callsubdelayed2, the subs Activity_Create and StartScan was called in Main_Scanner activity file. but after myscan.beginScan then end Sub in Sub StartScan, the process directly back to sub Activity_Resume in caller activity not in Main_Scanner activity.
There are numerous barcode scanner apps in the forum - I suggest you find one that works for you:)
 

mojako

Member
Licensed User
There are numerous barcode scanner apps in the forum - I suggest you find one that works for you:)
yes I know johan but I think this lib is good for us, because it's very fast to read EAN.
Correct me please, is this because I set the orientation to portrait rather than landscape?
 

Johan Schoeman

Expert
Licensed User
Longtime User
yes I know johan but I think this lib is good for us, because it's very fast to read EAN.
Correct me please, is this because I set the orientation to portrait rather than landscape?
Not sure - this lib is designed to be used in Landscape
 

dfrutos

Member
Licensed User
Longtime User
Hello, I have an error, when execute myscan.beginScan: "java.lang.RuntimeException: Unable to start activity ComponentInfo{b4a.example/com.jwetherell.quick_response_code.CaptureActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x0"

Can you help me?

Thank you!
 

Johan Schoeman

Expert
Licensed User
Longtime User
Hello, I have an error, when execute myscan.beginScan: "java.lang.RuntimeException: Unable to start activity ComponentInfo{b4a.example/com.jwetherell.quick_response_code.CaptureActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x0"

Can you help me?

Thank you!
You are probably missing the folders and files in the B4A project's /Objects/res folder. Make sure they are there and that the files have been set to READ ONLY. Do this after you have downloaded the B4A project but before you try to compile it the first time.
 

dfrutos

Member
Licensed User
Longtime User
Thank you for your answer. When i compile the example work it. But, when i implement the barcode code in other app i have error. I tried copy /object/res/ folder from original app example to my app and i set read only folder, but i have the same error. I copied the same manifiest... i don't know where is the error..

Thank you again.
 

Johan Schoeman

Expert
Licensed User
Longtime User
Thank you for your answer. When i compile the example work it. But, when i implement the barcode code in other app i have error. I tried copy /object/res/ folder from original app example to my app and i set read only folder, but i have the same error. I copied the same manifiest... i don't know where is the error..

Thank you again.
Are the files still in the various folders under /Objects/res once you have compiled your project? Just check. If not, then the files have been deleted because the files have not been set to read only.

Else please upload your sample project or send me a link to it from where I can download it.
 

Johan Schoeman

Expert
Licensed User
Longtime User
Thank you for your answer. When i compile the example work it. But, when i implement the barcode code in other app i have error. I tried copy /object/res/ folder from original app example to my app and i set read only folder, but i have the same error. I copied the same manifiest... i don't know where is the error..

Thank you again.
Have just tested it on three devices - one with Lollipop, one with KitKat, and one with Marshmallow. And it is working on all three of them
 

dfrutos

Member
Licensed User
Longtime User
Thank you, work it!

Other question: how can i use this barcode scanner with flash? I try turn on de light camera with fiddleAround lib, but when i start the scanner, with flash don't work scanner, and without flash scanner works.... any idea?

Thank you so much for your answer.
 

Johan Schoeman

Expert
Licensed User
Longtime User
Thank you, work it!

Other question: how can i use this barcode scanner with flash? I try turn on de light camera with fiddleAround lib, but when i start the scanner, with flash don't work scanner, and without flash scanner works.... any idea?

Thank you so much for your answer.
The original Github project does not provide for the flash to be switched on/off (usually by making use of the volume up/down button of a device) in class CaptureActivity.java. Will have to add some code to allow for the flash/torch to be available.

You will not be able to switch on/off the torch by using another library at the same time as what you are using this project. The camera is occupied and unless you release the camera another lib/project will not be able to access it.
 

dfrutos

Member
Licensed User
Longtime User
Its possible to add a torch method from b4a and using java code?

(the people works in the night reading barcodes and the torch is very useful)
 
Last edited:
Top