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:

icefairy333

Active 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,

but the code there is not error:sign0013: I will upload the code,you can see it yourself
 

bluedude

Well-Known Member
Licensed User
Longtime User
Sorry, library development is not my thing. So I conclude you don't have the same problem on your phone. I see some other people having the same problem.

Anyway, thanks for the response! Would love to use it but in my case it won't solve my problem.

Cheers,
 

joneden

Active Member
Licensed User
Longtime User
Hi All,

I've just tested on a Galaxy S2 running CM 10 - Android 4.1.2 and that is fine - I reworked so that a button press triggered the scan and then did a toastmessage to show the barcode.

I also tested on an Acer Liquid Glow - android 4.0.4 and again that worked fine.

Finally I did it on a Nexus and just got the blank screen even with the suggested manifest changes.

My list of improvements if ever possible would be as follows:
Portrait scanning (my app is portrait not landscape)
Embedding of the scan window in a panel (would a question to the developer of the Camera lib help - seeing as it's been done in that?)
Ability to get the bitmap that was seen at the time of the scan.

I'm going to see if I can help you add to the java....

Cheers,

J
 

Ohanian

Active Member
Licensed User
Longtime User
Hi,
i've tried the sample on Asus TF101, but got nothing, when i run the sample i only got a blinking red line, but the camera is not activated.
Any help?
 

javiers

Active Member
Licensed User
Longtime User
The camera can be displayed on a panel...

Hello,
The camera can be displayed on a panel, all in the same layout and activity?

thanks
 

susu

Well-Known Member
Licensed User
Longtime User
Hi Erel,

Could you please upgrade this wrapper library? I need turn flash on and capture scanned barcode option but this wrapper didn't support. I tried to use your CameraClass to turn on flash but the camera will be occupied so it can not scan barcode.

Thank you so much.
 

icefairy333

Active Member
Licensed User
Longtime User
I see.But in my demo I run it without scan twice(device:moto me860 with miui ics).and I have a application using this,I put it in a custom sub,it running well.
to #29 Will do it!
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).
 

icefairy333

Active Member
Licensed User
Longtime User
:signOops:Didn't say to me,I looked it and found that I can't using flash light well,so let the other friends to do it.:sign0013:
Hi Erel,

Could you please upgrade this wrapper library? I need turn flash on and capture scanned barcode option but this wrapper didn't support. I tried to use your CameraClass to turn on flash but the camera will be occupied so it can not scan barcode.

Thank you so much.
 

JTmartins

Active Member
Licensed User
Longtime User
Front camera.

Hi,

I've tried the sample, and the app does not run in the tablet. It compiles and as soon as the app goes to the tablet it immediately says " we are sorry B4A Example has been interrupted. "

However if I remove the Manifest lines, I don't get the error, but I get a black screen, and nothing else happens.


Help !!

Tablet OS ICS 4.03
B4A 2.50
 
Last edited:

icefairy333

Active Member
Licensed User
Longtime User
I don't know what's wrong with you.:sign0013:
Hi,

I've tried the sample, and the app does not run in the tablet. It compiles and as soon as the app goes to the tablet it immediately says " we are sorry B4A Example has been interrupted. "

However if I remove the Manifest lines, I don't get the error, but I get a black screen, and nothing else happens.


Help !!

Tablet OS ICS 4.03
B4A 2.50
 

JTmartins

Active Member
Licensed User
Longtime User
:)

Well there is nothing wrong with me personally...

If I use the provided sample "as is"...It throws the mentioned error.

So I was trying to understand why the error was appearing, as it's the first time I compile an app, send it to the device, and get an immediate error before anything else happens. (same on emulator)

As in B4A 2.5 some of the manifest stuff has moved to the code modules, screen orientation, full screen, etc...I tried to take those away from the Manifest editor, and set them in the proper region in Activity.

The error disappeared, but I just get a black screen.

And I really would like to test this to see if it fits my purposes...(currently using ABZxing, works ok, but depends on an external app...I would prefer not to depend on external apps.

Any help so that I could test this, would be welcomed.

Thanks

José
 

thedesolatesoul

Expert
Licensed User
Longtime User
hello icefairy333,
Nice work with the library and thanks for the source.
I am trying to import the source into eclipse but I get weird errors as if some reference is missing.
I was wondering to solve the Nexus 7 front camera problem. In your CameraManager class, in the openDriver method, I think we need to do the following:

B4X:
      cameraId = findFrontFacingCamera();
      if (cameraId < 0) {
        Toast.makeText(this, "No front facing camera found.",
            Toast.LENGTH_LONG).show();
      } else {
        camera = Camera.open(cameraId);
      }

 private int findFrontFacingCamera() {
    int cameraId = -1;
    // Search for the front facing camera
    int numberOfCameras = Camera.getNumberOfCameras();
    for (int i = 0; i < numberOfCameras; i++) {
      CameraInfo info = new CameraInfo();
      Camera.getCameraInfo(i, info);
      if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
        Log.d(DEBUG_TAG, "Camera found");
        cameraId = i;
        break;
      }
    }
    return cameraId;
  }

Can you build a lib version with this?
Thanks
 

NJDude

Expert
Licensed User
Longtime User
Ok, close but not cigar.

On the Nexus 7 now I see a blinking red line but no camera, also, the orientation, changing the scanner orientation on the Manifest from landscape to portrait works but the scanning doesn't work, this is not only on the Nexus 7.
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>)

Also, to get it on landscape or portrait the manifest and the line below must be updated:
B4X:
zx.isportrait = False

Question, would be possible to determine if the device has a front and back cameras? that will be great.

Thanks
 

icefairy333

Active Member
Licensed User
Longtime User
no idea.
:sign0161:
Ok, close but not cigar.

On the Nexus 7 now I see a blinking red line but no camera, also, the orientation, changing the scanner orientation on the Manifest from landscape to portrait works but the scanning doesn't work, this is not only on the Nexus 7.
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>)

Also, to get it on landscape or portrait the manifest and the line below must be updated:
B4X:
zx.isportrait = False

Question, would be possible to determine if the device has a front and back cameras? that will be great.

Thanks
 

icefairy333

Active Member
Licensed User
Longtime User
I like your solution and would like to implement it, but is this legal?
Haven't you used elements from the Zxing sourcecode to create your library? How else would this be possible....

zxing source licences:
B4X:
  "Source" form shall mean the preferred form for making modifications,
      including but not limited to software source code, documentation
      source, and configuration files.
   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at
 
Top