B4A Library QRCodeReaderView - QR Code Scanner that is also 100% embedded in B4A (new B4A lib files in post #8)

Here is another scanner that is 100% embedded in B4A. It wraps this Github project and will only scan QR Codes (it uses the ZXING engine for decoding scanned QR Codes). It will keep on reading QR codes for as long as what it finds a valid QR code. It is quite a "speedy" scanner. It does not require any other barcode scanner app to be installed on your device - it is 100% standalone. You can customize your B4A activity / UI by adding buttons, labels, panels, images, etc etc and change colors to your liking - 100% B4A customizable.

Note that a panel is the parent of the custom view but seeing that the original project extends Surface View it will punch a hole in the panel when the scanner starts.

Also note the permissions in the B4A project's manifest file (I know majority are redundant for this project).

You will have to handle consecutive / continuous scans of the same QR code within your B4A code.

Posting the following:
1. B4A project
2. B4A library files (3 x jar and 1 x xml) - copy them to your additional library folder.

EDIT: UPDATED LIBRARY FILES IN POST #6 THAT WILL NOT RAISE AN EVENT IN B4A IF TWO CONSECUTIVE SCANS OF THE SAME QR CODE OCCURS

1.png



Scanner.png



2.png


Some sample code:

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

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 qrcrv As QRCodeReaderView

    Private b1 As Button
    Private b2 As Button
    Private p1 As Panel
    Private l1 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")

    qrcrv.Visible = False


End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub b1_Click


    qrcrv.Visible = True
    DoEvents
    qrcrv.startScan

End Sub
Sub b2_Click

    qrcrv.stopScan
    DoEvents
    qrcrv.Visible = False

End Sub

Sub qrcrv_result_found(retval As String)

    Log("B4A: " & retval)
    l1.Text = retval

End Sub


The library:

QRCodeReaderView
Author:
Github: David L\u00e1zaro, Wrapped by: Johan Schoeman
Version: 1
QRCodeReaderView
Events:

  • result_found (retval As String)
Fields:
  • ba As BA
Methods:
  • BringToFront
  • DesignerCreateView (base As PanelWrapper, lw As LabelWrapper, props As Map)
  • Initialize (EventName As String)
  • Invalidate
  • Invalidate2 (arg0 As Rect)
  • Invalidate3 (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
  • IsInitialized As Boolean
  • RemoveView
  • RequestFocus As Boolean
  • SendToBack
  • SetBackgroundImage (arg0 As Bitmap)
  • SetColorAnimated (arg0 As Int, arg1 As Int, arg2 As Int)
  • SetLayout (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
  • SetLayoutAnimated (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int, arg4 As Int)
  • SetVisibleAnimated (arg0 As Int, arg1 As Boolean)
  • startScan
  • stopScan
Properties:
  • Background As Drawable
  • Color As Int [write only]
  • Enabled As Boolean
  • Height As Int
  • Left As Int
  • Tag As Object
  • Top As Int
  • Visible As Boolean
  • Width As Int
You can download and test any posting of mine in this thread but if you want to use it then you need to
 

Attachments

  • QRCodeReaderViewLibFiles.zip
    498.1 KB · Views: 3,533
  • b4aQRCodeReaderView.zip
    8.9 KB · Views: 3,129
Last edited:

huffy

Member
Licensed User
Longtime User
Hi Johan,

Great library thanks - it works a treat for the project I'm working on! Donation on its way.. :)

One question, is it possible to use this in landscape orientation?

Thanks,
Mike
 

Mahares

Expert
Licensed User
Longtime User
One question, is it possible to use this in landscape orientation?
Yes. It works for me.
Change the line in the IDE to read landscape like seen below instead of portrait. You may also want to create a new layout 480x320 or modify your existing layout to adjust the placement and display all views. You can also switch from one orientation to the other.
B4X:
#SupportedOrientations: landscape
 

huffy

Member
Licensed User
Longtime User
Thanks Mahares, I tried that but the camera is rotated 90 degrees when in landscape - see attached screenshot of a example app. Any ideas?

Thanks

Screenshot_2016-03-22-13-18-16.png
 

Mahares

Expert
Licensed User
Longtime User
Here is attached the example with 2 layouts I modified and ran, and it scans QR codes very well for me on my devices. Please try it. I hope it suits your device.
 

Attachments

  • huffyQRcodeViewer032116.zip
    9.1 KB · Views: 462

huffy

Member
Licensed User
Longtime User
I appreciate your help but the camera is still rotated 90 degrees using your example.

I guess it must be the device I'm using (Samsung Galaxy Tab 3 Lite 7.0")

Thanks again
 

Johan Schoeman

Expert
Licensed User
Longtime User
Hi Johan,

Great library thanks - it works a treat for the project I'm working on! Donation on its way.. :)

One question, is it possible to use this in landscape orientation?

Thanks,
Mike
Thanks Mike! I hope the "hack" that I have sent you will do the trick.
 

so27

Active Member
Licensed User
Longtime User
Can I, for example, open an image with QR Code and then read the QR code? So completely without camera.

I try the scanned QR save. But Image remains white. Does anyone know why?
B4X:
    Dim cnv As Canvas
    cnv.Initialize(qrcrv)
    Dim Out As OutputStream
    Out = File.OpenOutput(File.DirRootExternal, "qrcode.png", False)
    cnv.Bitmap.WriteToStream(Out, 100, "PNG")
    Out.Close
 
Last edited:

Johan Schoeman

Expert
Licensed User
Longtime User
Can I, for example, open an image with QR Code and then read the QR code? So completely without camera.

The library does not make provision for that option at present. There is a library somewhere in the forum that will decode the barcode (1D and 2D) from an image


I try the scanned QR save. But Image remains white. Does anyone know why?

qrcrv is not a bitmap
 

so27

Active Member
Licensed User
Longtime User
The library does not make provision for that option at present. There is a library somewhere in the forum that will decode the barcode (1D and 2D) from an image




qrcrv is not a bitmap

Okay, thank you.
 

joilts

Member
Licensed User
Longtime User
Great Lib. Works perfect in many phones. Only one point to see if I can find help: On Samsung S6 Edge, the image get "out of focus" sometimes. Is there a way to request the camera to focus again?

Thanks,
 

SlashIT

Member
Licensed User
Longtime User
question: Is it possible to retrieve the x / y position of the upper left corner of the qrcode?
thanks
 

Johan Schoeman

Expert
Licensed User
Longtime User
question: Is it possible to retrieve the x / y position of the upper left corner of the qrcode?
thanks
I guess it is possible but I have no intention to dig through the ZXING core code to see if we can somehow find a way to bring back the left top x/y position. If you can find it then let me know and I will try to add code to bring it back
 

Johan Schoeman

Expert
Licensed User
Longtime User
Great Lib. Works perfect in many phones. Only one point to see if I can find help: On Samsung S6 Edge, the image get "out of focus" sometimes. Is there a way to request the camera to focus again?

Thanks,
Will see if I can somehow force an auto focus. The original Github code seems OK and should actually do it automatically
 

Alisson

Active Member
Licensed User
Johan, good morning.
I'm using your library to a similar authentication with whatsapp:

upload_2016-8-22_12-31-49.png

https://web.whatsapp.com/


I press the start button, but does not show the camera image to read the QRcode.
The camera captures the image is black.
When I press the stop button or the back of the phone button, the application hangs and the following error appears:

upload_2016-8-22_12-31-0.png


Can you help me please?

Thnaks very much!
 

Johan Schoeman

Expert
Licensed User
Longtime User
Johan, good morning.
I'm using your library to a similar authentication with whatsapp:

View attachment 47212
https://web.whatsapp.com/


I press the start button, but does not show the camera image to read the QRcode.
The camera captures the image is black.
When I press the stop button or the back of the phone button, the application hangs and the following error appears:

View attachment 47211

Can you help me please?

Thnaks very much!
This is the B4A manifest file of the project that I have posted:
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: https://www.b4x.com/forum/showthread.php?p=78136
'AddManifestText(
'<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="14"/>
'<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:theme, "@android:style/Theme.Holo")
'End of default text.


'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: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="17"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
AddManifestText(<uses-feature android:name="android.hardware.telephony" android:required="false" />)
AddManifestText(<uses-feature android:name="android.hardware.camera" android:required="false" />)
AddManifestText(<uses-feature android:name="android.hardware.camera.autofocus" android:required="false" />)
AddManifestText(<uses-feature android:name="android.hardware.camera.flash" android:required="false" />)
'AddPermission("android.permission.ACCESS_COARSE_LOCATION")
AddPermission("android.permission.INTERNET")
AddPermission("android.permission.ACCESS_FINE_LOCATION")
AddPermission("android.permission.WAKE_LOCK")
AddPermission("android.permission.DEVICE_POWER")
'AddPermission("android.permission.ACCESS_COARSE_UPDATES")
AddPermission("android.permission.READ_PHONE_STATE")
AddPermission("android.permission.VIBRATE")
AddPermission("android.permission.CAMERA")
AddPermission("android.permission.FLASHLIGHT")
AddPermission("android.hardware.camera")
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")

Update your B4A project's manifest file accordingly and then it will work (have tested your sample project that you have sent me and when the manifest is updated it is all OK).
 

Johan Schoeman

Expert
Licensed User
Longtime User
Hi Johan, great job. I've same problem, can you also help me? Thanks
@huffy has donated for the "hack". So best you ask him if he is OK with me publishing it on the forum for everyone else to use.
 
Top