xamarin / GooglePlayServicesComponents

Other
315 stars 148 forks source link

How to use BarcodeScanning with Xamarion.Google.MlKit.Vision.BarcodeScanning #450

Open ComptonAlvaro opened 3 years ago

ComptonAlvaro commented 3 years ago

I am trying to develop an Xamarion.Android application using Google MLLit to can scan QR codes. I am trying to follow the documentation of Google here: https://developers.google.com/ml-kit/vision/barcode-scanning/android

I create a blank project of Xamarin.Android and in the main activity, I tried to use this code:

            var options = BarcodeScannerOptions.Builder
                .setBarcodeFormats(Barcode.FormatQrCode)
                .build();

Then problem is that BarcodeScannerOptions.Builder has not a .setBarcodeFormats method, so I don't know how to continue.

I could try to find an example here in the examples code, but I don't see any example with MLKit, it is with GSM, and when I try to open this project, it says that it can't be found the GSM namespace.

Where coudl I use MLKit or where I could find an example with the code for Xamarin.Android and MLKit?

Thanks.

moljac commented 3 years ago

@ComptonAlvaro

Thanks for the feedback.

Then problem is that BarcodeScannerOptions.Builder has not a .setBarcodeFormats method, so I don't know how to continue.

OK. This might be bindings issue (me or tools), but I need to dive deeper into generated code.

I could try to find an example here in the examples code, but I don't see any example with MLKit, it is with GSM, and when I try to open this project, it says that it can't be found the GSM namespace.

This might be the issue. You are using GSM API (nugets/artifacts). I need minimal repro sample in order to investgate.

Where coudl I use MLKit or where I could find an example with the code for Xamarin.Android and MLKit?

Well I did not have time to port any official sample to Xamarin.Android and doubt that someone as already done it.

So you should try porting following samples:

https://github.com/googlesamples/mlkit

https://github.com/googlesamples/mlkit/tree/master/android

https://github.com/googlesamples/mlkit/tree/master/android/vision-quickstart

Jerome-Liger commented 3 years ago

@ComptonAlvaro , for barcode Scanning, use the plugin https://github.com/Redth/ZXing.Net.Mobile It's stable since years, maintained and updated frenquently, and it's a powerfull barcode scanner plugin with a lot of configurations... I always use this plugin in production-apps ;-)