B4A Library ZXingLib(integration version)by icefairy333

integration version
zxing 2.1 inside
no need to install zx scaner or other apk,just a jar and xml file copy it to b4a library dir,and then use it well.

demo:
B4X:
'Activity module
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 zx As Zxing_B4A
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("Layout1")
zx.BeginScan("myzx")
End Sub
Sub myzx_result(atype As String,Values As String)
   Log("type:"&atype&"values:"&Values)
   Msgbox("type:"&atype&"values:"&Values,"result")
End Sub
Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
and you must add last text to manifest editor:
B4X:
AddApplicationText(<activity android:name="ice.zxing.CaptureActivity"
         android:screenOrientation="landscape" android:configChanges="orientation|keyboardHidden"
         android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
         android:windowSoftInputMode="stateAlwaysHidden">
      </activity>)

lib doc:
b4aZXing
Author: IceFairy333
Version: 1.5
  • Zxing_B4A
    Events:
    • result (atype as String As , Values as String As )
    Fields:
    • isportrait As Boolean
    • useFrontCam As Boolean
    Methods:
    • BeginScan (EventName As String)
      please handle the event
      add this to manifest:<activity android:name="ice.zxing.CaptureActivity"
      android:screenOrientation="landscape" android:configChanges="orientation|keyboardHidden"
      android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
      android:windowSoftInputMode="stateAlwaysHidden"></activity>
    Permissions:
    • android.hardware.camera
    • android.hardware.camera.autofocus
    • android.permission.CAMERA
    • android.permission.FLASHLIGHT
    • android.permission.VIBRATE
    • android.permission.WRITE_EXTERNAL_STORAGE
lib doc:
b4aZXing
Author: IceFairy333
Version: 1.2
  • Zxing_B4A
    Events:
    • result (atype as String As , Values as String As )
    Methods:
    • BeginScan (EventName As String)
      please handle the event
      add this to manifest:<activity android:name="ice.zxing.CaptureActivity"
      android:screenOrientation="landscape" android:configChanges="orientation|keyboardHidden"
      android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
      android:windowSoftInputMode="stateAlwaysHidden"></activity>
    Permissions:
    • android.hardware.camera
    • android.hardware.camera.autofocus
    • android.permission.CAMERA
    • android.permission.FLASHLIGHT
    • android.permission.VIBRATE
    • android.permission.WRITE_EXTERNAL_STORAGE

anyone who has the scan twice,can download the library src to check it on your device,in my phone it works fine:signOops:

notice by Erel:The second scan happens because zx.BeginScan is called from Activity_Create. The activity is recreated when you change the orientation during the scanning.

The solution is simple. Move this call to a different sub (Button_Click for example).
 

Attachments

  • zxdemo&lib.zip
    255.5 KB · Views: 2,401
  • b4aZxingLibsrc.zip
    325.9 KB · Views: 2,063
  • b4azxing1.5.zip
    249.2 KB · Views: 2,152
Last edited:

bluedude

Well-Known Member
Licensed User
Longtime User
Hi, it works on my phone.

Are you using the latest Zxing version? And would it be possible in the end to put the scanning screen in a panel?

Unfortunately it does not support my frontcamera of the Nexus 7, this is a problem with the standard Play Store Zxing download too.
 

icefairy333

Active Member
Licensed User
Longtime User
for Nexus 7 you should add this code to manifes editor:
B4X:
' Don't require camera, as this requires a rear camera. This allows it to work on the Nexus 7 
AddManifestText(<uses-feature android:name="android.hardware.camera" android:required="false"/>
  <uses-feature android:name="android.hardware.camera.front" android:required="false"/>
  <uses-feature android:name="android.hardware.camera.autofocus" android:required="false"/>
  <uses-feature android:name="android.hardware.camera.flash" android:required="false"/>
  <uses-feature android:name="android.hardware.screen.landscape"/>
  <uses-feature android:name="android.hardware.wifi" android:required="false"/>
  <uses-feature android:name="android.hardware.touchscreen" android:required="false"/>)
@And would it be possible in the end to put the scanning screen in a panel?
I didn't know how to pass the bitmap to the event from library,sorry~ for example put the bitmap to a intent
 
Last edited:

airblaster

Active Member
Licensed User
Longtime User
Very useful library, thanks for writing and publishing it!
Would be great if you could somehow set some text to be displayed on Screen while the scanner is running, but I guess most users should understand what to do even without instructions.

By the way, is the library licensed under creative commons CC BY 3.0 like most B4A libraries (see here: http://www.b4x.com/android/wiki/index.php/Libraries)?
 

NJDude

Expert
Licensed User
Longtime User
I just tried your sample on a Nexus 7, I added the code you mentioned to make it work on a Nexus 7 and it doesn't work, I just see a black screen.

On my EVO (ICS), it works but I have to scan the barcode twice to get the result.
 
Last edited:

bluedude

Well-Known Member
Licensed User
Longtime User
You have to scan twice

I also discovered there is a bug in this library, you need to scan twice indeed to get results which is not really handy.

Cheers,
 

susu

Well-Known Member
Licensed User
Longtime User
I confirm that it scaned twice at the first time you run the app. After that, you only need to scan one time.
 

joneden

Active Member
Licensed User
Longtime User
Funny timing on this - I only posted the link to the direct integration (ZXing QR Reader Direct Integration | AndroidAZ) the other day. Did you use the same guide?

Using the standard app I cannot get a copy of the picture taken at the time of the scan and also NFC data doesn't end up in my app so I'm looking at using this to get some more info.

Will you be looking at those features in your version or should I carry on working on my interpretation?

Cheers

Jon
 

joneden

Active Member
Licensed User
Longtime User
doh, link didn't work.

BTW, you said about not knowing how to pass the bitmap via the intent in one of the earlier posts - couldn't you just save the file then pass the filename back?

Then allow the calling app to get the file and do something with it...

Cheers

Jon
 

bluedude

Well-Known Member
Licensed User
Longtime User
icefairy

Can you fix the need to scan twice? Otherwise I will need to keep working with the other library created for the scanner.

On first recognition of a QR code the event is never triggered and no results are returned.

Cheers,
 

icefairy333

Active Member
Licensed User
Longtime User
I don't know your meaning.when you call zx.BeginScan("zx") the library will start another activity for result ,the captureactivity return the result and finish itself,library pass the result to our b4a activity ,,what's wrong with this ?
B4X:
LogCat connected to: TA7440A61H
--------- beginning of /dev/log/main


--------- beginning of /dev/log/system


** Activity (main) Create, isFirst = true **


** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
QR_CODE:http://bbc.co.uk/programmes###myzx_result
sending message to waiting queue (OnActivityResult)
running waiting messages (1)
type:QR_CODEvalues:http://bbc.co.uk/programmes
** Activity (main) Resume **
here is the logcat form demo ,the first value is output by library,and the second one is output by b4a demo activity .where is the problem ?

test on :ICS
 
Last edited:

susu

Well-Known Member
Licensed User
Longtime User

joneden

Active Member
Licensed User
Longtime User
Given that any lib created will be using an open source lib (ZXing). It would be nice to have a community effort getting this going - anyone agree?

That would help us all get what we want from an embedded lib.
 

bluedude

Well-Known Member
Licensed User
Longtime User
I'm using a Galaxy Nexus and what happens when I use your sample is this:

Scanning code and image is captured but no event is generated
Scanning again and image is captured again and event is generated.

So conclusion is that I have to keep the QR code in the box so that it recognizes the code twice, only the second time an event is generated.

You must be seeing this, cannot imagine you don't have this on your phone. Will try another phone and see what happens.

Cheers,
 
Top