Help to bind Zxing library to scan barcode on Android

LiveCode Builder is a language for extending LiveCode's capabilities, creating new object types as Widgets, and libraries that access lower-level APIs in OSes, applications, and DLLs.

Moderators: LCMark, LCfraser

yunior.portilla
Posts: 28
Joined: Sat May 30, 2020 12:50 am

Help to bind Zxing library to scan barcode on Android

Post by yunior.portilla » Wed Jun 17, 2020 5:42 pm

I'm trying to use the ZXing library from LiveCode Builder to create a barcode reading mechanism, but it doesn't work for me, it must be that I'm doing something wrong.

I am stuck and actually the new LiveCode Barcode Scanner widget requires the Google Play Service functionalities, which makes my app not run on devices that don't have Google Play Service.

In ZXing the IntentIntegrator class is invoked and the initiateScan method is passed to it, that in Android Studio works perfectly for me, raise the camera and scan perfect ...

The results are returned in onActivityResult ... If you could bind these methods from LiveCode Builder awesome. I copied the core and embedded ZXING libraries to the code / jvm-android folder to my LCB project, but it did not work.

yunior.portilla
Posts: 28
Joined: Sat May 30, 2020 12:50 am

Re: Help to bind Zxing library to scan barcode on Android

Post by yunior.portilla » Thu Jun 18, 2020 9:22 pm

I downloaded the .jar from the XZing site and incorporated it into my LCB project at code / jvm-android however when I make the calls it didn't work. I share the code to see where I am failing.

The code has other examples that I put into practice following the basic example of using an external java library.

Thank you.
Attachments
yBarcode.rar
(24.02 KiB) Downloaded 349 times

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Help to bind Zxing library to scan barcode on Android

Post by Klaus » Fri Jun 19, 2020 8:07 am

Hi yunior,

please only one thread per issue!
Will delete your posting in the ANDROID forum, LivecodeBuilder seems to be the correct forum for this..


Best

Klaus

sphere
Posts: 1145
Joined: Sat Sep 27, 2014 10:32 am
Location: Earth, Except when i Jump

Re: Help to bind Zxing library to scan barcode on Android

Post by sphere » Fri Jun 19, 2020 10:26 am

why don't you sideload Google apps on those devices?
That's maybe a simpler solution than the path you try to walk now.
Check https://opengapps.org/ and https://wiki.lineageos.org/gapps.html

It's also used by people who install LineageOS which does not incorporate company's bloatware.

Sometimes you need another loader, and sometimes you can sideload it via an APK. Check and search for Gapps. There are also light versions, just see what you need for the minimum to get it working.

yunior.portilla
Posts: 28
Joined: Sat May 30, 2020 12:50 am

Re: Help to bind Zxing library to scan barcode on Android

Post by yunior.portilla » Thu Jun 25, 2020 6:43 pm

I am obliged for my application to provide a solution independent of Google Play services, lately there are many versions of the operating system that do not have the services of Google Play Service, which means that the excellent Android barcode Widget does not work for me on those devices.

Currently he worked on an educational project that needs to read a Qr code to obtain the student's data, and for example in China Google services are not used so my application does not work there.

Hence my need to find a solution with ZXING as the MergZXing barcode reader variant for IOs that LiveCode has.

In this endeavor I tried to bind liveCode with .arr android-zxing-embbebed.aar but it didn't work for me.

I am preparing an example to share it to see if you can help me.

Regards

yunior.portilla
Posts: 28
Joined: Sat May 30, 2020 12:50 am

[SOlved] Re: Help to bind Zxing library to scan barcode on Android

Post by yunior.portilla » Wed Aug 19, 2020 7:09 pm

I am pleased to share with the community the library with its examples of how to integrate ZXing into LiveCode through LiveCode Builder. Here you have the links to download the example and the library developed that integrates ZXing. It is working very fast for me.

https://github.com/portilla/yBarcode

Regards

sphere
Posts: 1145
Joined: Sat Sep 27, 2014 10:32 am
Location: Earth, Except when i Jump

Re: Help to bind Zxing library to scan barcode on Android

Post by sphere » Wed Aug 19, 2020 7:44 pm

This is great!

Downloaded it and will try it out.
So the main advantage is that it is independent of Google dependencies and/or MergZXing ?
But still needs Indy for the camera control.
Correct?

yunior.portilla
Posts: 28
Joined: Sat May 30, 2020 12:50 am

Re: Help to bind Zxing library to scan barcode on Android

Post by yunior.portilla » Wed Aug 19, 2020 8:00 pm

Hello,

If the library is totally independent of Google and mergZXing, precisely what I did was integrate the free ZXing project in the library that I developed with LiveCode Builder so that I did not need anything to read a Qr code.

Previously LiveCode brings a library to generate Qr codes but not to read them, this library solves that problem and without depending in the case of Android on Google Play services.

Unfortunately in the community version the methods to manipulate the camera internally are not available as they appear in the Indy version with the "CameraControl", in the example there is that complete integration. For now I am working on a widget that will raise the device's camera through the android SDK so that in the community version I can also use the second example.

Thank you

sphere
Posts: 1145
Joined: Sat Sep 27, 2014 10:32 am
Location: Earth, Except when i Jump

Re: Help to bind Zxing library to scan barcode on Android

Post by sphere » Wed Aug 19, 2020 9:12 pm

Hi Portilla,

wow that sounds great!

I just tested it on my Android phone and it works great! When I scan with the camera it gives the nr's of the QR-code. It's fast too.

I hope you are wanting to show how you integrated it via lcb, so that we can learn from it too. As many people still have many questions on how to integrate Android sdk stuff or AAR's into lcb.

Fantastic Job!

thanks a lot.

PaulDaMacMan
Posts: 616
Joined: Wed Apr 24, 2013 4:53 pm
Contact:

Re: Help to bind Zxing library to scan barcode on Android

Post by PaulDaMacMan » Thu Aug 20, 2020 11:30 pm

Bravo!
It would be really great if you'd release the source .lcb file too as there isn't all that many examples of using LCB with JAVA around.
Thanks for releasing this.
My GitHub Repos: https://github.com/PaulMcClernan/
Related YouTube Videos: PlayList

SparkOut
Posts: 2839
Joined: Sun Sep 23, 2007 4:58 pm

Re: Help to bind Zxing library to scan barcode on Android

Post by SparkOut » Fri Aug 21, 2020 7:29 am

Well done! Thank you for this.
I would also love to see the lcb source, I am sure many other people would be grateful for this as well.
It is a big step from making the pink ball widget to a FFI interface, and this real-world example would be a fantastic way to expand the user base competence.

yunior.portilla
Posts: 28
Joined: Sat May 30, 2020 12:50 am

Re: Help to bind Zxing library to scan barcode on Android

Post by yunior.portilla » Fri Aug 21, 2020 3:43 pm

Hello,

I am happy to share the LiveCode Builder source code with you and the community. At the moment if they have accounts in gitlab they send me the user here and I add them as members to the project that I have of yBarcode in gitLab so they can see what is done.

Excuse my English because I am Spanish speaking.

I have not completely released the code to work on the part of the widget that will integrate the camera and make the project much more complete.

Although it is already a step forward to have a library that reads the qr code from an image.

Regards.

julianmoors
Posts: 5
Joined: Sun May 23, 2021 2:48 pm

Re: Help to bind Zxing library to scan barcode on Android

Post by julianmoors » Sat May 29, 2021 10:37 am

Hello Yunior,

Thank you for posting this very informative thread. I'm currently using the Community version of LiveCode and thinking ahead of time I would need the Android Barcode Scanner to be of use when building my prototype. As I'm not a professional developer, I'm not in the position where I could purchase the Indy version of LiveCode, however I would be willing to purchase a LiveCode extension providing that I would have access to the LCB source file. Would you be willing to make this happen?

My username for Gitlab is julianmoors. Could you please add me to the project for the LCB source file?

Hope to hear back from you soon pal.

sphere
Posts: 1145
Joined: Sat Sep 27, 2014 10:32 am
Location: Earth, Except when i Jump

Re: Help to bind Zxing library to scan barcode on Android

Post by sphere » Mon May 31, 2021 8:00 pm

I think the project is dead.
I have access to their gitlab page, but since last year there is nothing happening.
Too bad, I looked forward to it also.

PaulDaMacMan
Posts: 616
Joined: Wed Apr 24, 2013 4:53 pm
Contact:

Re: Help to bind Zxing library to scan barcode on Android

Post by PaulDaMacMan » Fri Jun 04, 2021 1:42 am

this is the entirety of the LCB code of yBarcode.lcb lib, combining the extracted file from GitHub (which also has the zxing java jar file it's dependent on) and the one posted above:

Code: Select all

library cu.tgraf.ypr.ybarcode

metadata title is "Android ZXing Barcode Scanner"
metadata author is "Yunior Portilla Rodríguez"
metadata version is "1.0.0"

use com.livecode.foreign
use com.livecode.java

/*Retorna el contexto de la Aplicación*/
__safe foreign handler _JNI_GetAndroidEngine() returns JObject binds to "java:com.runrev.android.Engine>getEngine()Lcom/runrev/android/Engine;!static"
__safe foreign handler _JNI_GetEngineContext(in pEngine as JObject) returns JObject binds to "java:android.view.View>getContext()Landroid/content/Context;"

/*Retorna el idioma de la Aplicación*/
__safe foreign handler JavaGetDefaultLocale() returns JObject binds to "java:java.util.Locale>getDefault()Ljava/util/Locale;!static"
__safe foreign handler JavaLocaleDisplayName(in pLocale as JObject) returns JObject binds to "java:java.util.Locale>getDisplayName()Ljava/lang/String;"

/*Test de utilización de un java externo*/
__safe foreign handler _JNI_SayHello() returns JString binds to "java:cu.livecode.library.ybarcode.YBarcodeLCBZXing>sayHelloAndroid()Ljava/lang/String;!static"

/*Integrando ZXing para escanear el Códigos de barra*/
__safe foreign handler _JNI_IntentIntegrator(in pActivity as JObject) returns JObject binds to "java:com.google.zxing.integration.android.IntentIntegrator>new(Landroid/content/Context;)Lcom/google/zxing/integration/android/IntentIntegrator?ui"
__safe foreign handler _JNI_InitiateScan(in pActivity as JObject, in pInstance as JObject) returns nothing binds to "java:com.google.zxing.integration.android.IntentIntegrator>initiateScan()V?ui"

private variable sActivity as optional JObject

public handler SayHello() returns String
   return StringFromJString(_JNI_SayHello())
end handler

public handler SayAndroidTest() returns String
   return "TEST"
end handler

public handler GetDefaultLocaleDisplayName() returns String
   variable tLocale as JObject
   put JavaGetDefaultLocale() into tLocale

   variable tDisplay as JString
   put JavaLocaleDisplayName(tLocale) into tDisplay

   return StringFromJString(tDisplay)
end handler

public handler startBarcodeScanner() returns Boolean
   if sActivity is nothing then
      put _JNI_GetEngineContext(_JNI_GetAndroidEngine()) into sActivity
   end if

   variable tInstance as JObject
   put _JNI_IntentIntegrator(sActivity) into tInstance

   _JNI_InitiateScan(sActivity,tInstance)
end handler

/**
Summary: Se obtiene el texto que contiene la imagen del Qr Code .

Platforms: android 5.0 o superior

Example:
getQrCodeFromImage("/storage/emulated/0/Android/data/cu.tgraf.zxingintegration/files/test.jpeg")

Parameters:
pPath: Un string que contiene el camino físico de la imagen.

Returns: Devuelve un string con el valor del Qr si es satisfactoria la lectura del Qr Code;
"Not found." en caso de que no se encuentre un Qr Code en la imagen;
"Error: Invalid image format." si el formato de la imagen no es válido;
"Error: Image file does not exist." si el camino del fichero no existe.

Description:
Para que funcione correctamente el método hay que darle permisos a la aplicación para que "Write External Storage".
*/

public handler getQrCodeFromImage(in pPath as String) returns String
   variable tResult as JString

   put _JNI_readQRCodeFromImage(StringToJString(pPath)) into tResult
   return StringFromJString(tResult)
end handler

end library

My GitHub Repos: https://github.com/PaulMcClernan/
Related YouTube Videos: PlayList

Post Reply

Return to “LiveCode Builder”