Forum Cross Platform with Xamarin

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

ZxingSharp.Mobile - Cross Platform Barcode Scanning

1235»

Posts

  • Hi All,
    I hope this helps someone else out there. With version 1.4.0, I was experiencing this same issue with the scanner locking up after 4-5 scans when using the OS7 built in AVCaptureSession MetadataObject barcode scanning.

    I fixed my problem by adding the same code for suggested fix #71 to the StopScanning method in the AVCaptureView.cs file (found at https://github.com/Redth/ZXing.Net.Mobile/commit/3f4267e6710dba4c6d4934cac2bddbe613807243). Once I did that, my problem went away.

    Once again, thanks for the efforts on this project. They are greatly appreciated.

  • JuanJChiwJuanJChiw ESMember ✭✭

    It seems that component that it's now in the componente store 1.4.3 version is not working on android, I just downloaded the code from github compile it and add the reference to the project and voila...

    thanks for the great library @Redth.

  • JonathanDickJonathanDick CAXamarin Team, Developer Group Leader Xamurai

    @JuanJChiw‌ yep, sorry about that, 1.4.3 has a bug in it where in some timezones the scanning doesn't work on Android. I'm putting an update out sometime today (it needs to be approved still after that). So either hold tight, or go to the github repo and grab the fixed code :)

  • JuanJChiwJuanJChiw ESMember ✭✭

    @Redth‌ Using the Component 1.4.4 works great. Thanks for the update

  • vipinshuklavipinshukla INMember

    Everything is fine. But Zxing does not scan smaller barcodes. Can anyone tell the solution for scanning smaller barcodes through ZXing? I mean to say smaller in height and width.

  • JonathanDickJonathanDick CAXamarin Team, Developer Group Leader Xamurai

    @vipinshukla‌ the best thing you can do is go to https://github.com/Redth/ZXing.Net.Mobile and open a new issue there, and be sure to attach images of the barcodes you are having trouble scanning!

  • xiaoyuandlgxiaoyuandlg USMember
    edited June 2014

    Sounds like a very interesting topic to me. I am also new to the .net barcode reader, the discussion here offered me much information. A helpful good thread to me! Good sharing!

  • frank.1306frank.1306 USMember

    Nice job! Thanks a lot.

  • @Redth,

    I have been working on a Xamarin Forms project over the last several months, and was able to get ZXing component version 1.4.7 working in Android, before taking a couple months off to work on other projects.

    I've come back to the project in the last week, and upgraded to 1.5.1.

    The documentation is now out of date as it continues to mention that Android must pass a Context into the Constructor, while the constructor no longer accepts any arguments.

    When I do issue a Scan() command, my application crashes with no error information.

        //var scanner = new MobileBarcodeScanner( Forms.Context )
                var scanner = new MobileBarcodeScanner( )
                {
                    UseCustomOverlay = false,
                    BottomText = "Scanning will happen automatically",
                    TopText = "Hold your camera about \n6 inches away from the barcode",
    
                };
    
         var result = await scanner.Scan( );
    

    Please let me know what additional info I can supply that can be useful.

  • SchalkBowerSchalkBower NZUniversity

    @billspain ZXing 1.5.1 is working fine on my Xamarin Forms project on both iOS and Android. I'm currently using it like:

            var scanner = new MobileBarcodeScanner();
            scanner.TopText = "Hold your camera about \n6 inches away from the barcode";
            scanner.BottomText = "Scanning will happen automatically";
            scanner.CancelButtonText = "";
    
            var options = new MobileBarcodeScanningOptions();
            options.PossibleFormats = new List<ZXing.BarcodeFormat>();
            options.PossibleFormats.Add(ZXing.BarcodeFormat.QR_CODE);
    
            var result = await scanner.Scan(options);
    

    without any issue. When are you calling the Scan? Is it inside a modal or a normal navigation page? Is it triggered in the OnAppearing event?

  • JonathanDickJonathanDick CAXamarin Team, Developer Group Leader Xamurai

    @billspain thanks, I've updated the README, but you should see in the sample as well that you should really call the following code on android so that the library can keep track of the currently visible Activity and use that to open the scanner from:

    //NOTE: On Android you should call the initialize method with an application instance
    #if __ANDROID__
    // Initialize the scanner first so it can track the current context
    MobileBarcodeScanner.Initialize (Application);
    #endif
    

    If you don't call this, then the application context will be used instead which can sometimes work, and sometimes cause issues which you're obviously seeing...

    The main reason for this change is to make the basic API PCL compatible. You can now use the ZXing.Net.Mobile nuget package as a PCL which should help with Xamarin.Forms :)

    Cheers!

  • guys - thanks for your help. However, I've incorporated changes based on your input and tested on different hardware devices, and it still crashes on the Scan() command.

    The code is ultimately triggered by a button press by the user in a Xamarin Forms application, in this case built for Android.

    The scanning code is in a library that is an Android-specific implementation of an Interface which is called by a Portable Class Library that has been called by the Forms application. The Android-specific scanning library is using ZXing.Net.Mobile version 1.5.1.

    The Xamarin Forms app is using Xamarin.Forms 1.4.4.6392.

    I am using Visual Studio 2015 on a Windows 10 system.

    I use a Dependency-like service to register OS-dependent libraries, so in my MainActivity.cs I have the following code which is run on application startup:

          XPScannerDroid.XPScannerDroid droidScanner = new XPScannerDroid.XPScannerDroid();
                droidScanner.AndroidApplication = Application;
                eDRPCL.AppCore.fx.m_scanner = droidScanner;
    

    The Android scanning library looks like this:

       public class XPScannerDroid : XPScannerBasePCL.XPScannerBasePCL
        {
            public Android.App.Application AndroidApplication { get; set; }
    
            public XPScannerDroid ( )
                : base()
            {
                AndroidApplication = null;
            }
            public async override Task<ScanResult> Scan ( )
            {
                try
                {
                    //NOTE: On Android you should call the initialize method with an application instance 
                    if ( AndroidApplication != null )
                    {
                        // Initialize the scanner first so it can track the current context 
                        MobileBarcodeScanner.Initialize( AndroidApplication );
    
                        //var scanner = new MobileBarcodeScanner( Forms.Context )
                        var scanner = new MobileBarcodeScanner()
                        {
                            UseCustomOverlay = false,
                            BottomText = "Scanning will happen automatically",
                            TopText = "Hold your camera about \n6 inches away from the barcode",
                            CancelButtonText = "",
                        };
    
                        var options = new MobileBarcodeScanningOptions
                        {
                        };
                        options.PossibleFormats = new System.Collections.Generic.List<ZXing.BarcodeFormat>();
                        options.PossibleFormats.Add( ZXing.BarcodeFormat.CODE_128 );
    
            // Crashes on the following line...
                        ZXing.Result result = await scanner.Scan( options );
    
            // (code omitted...)
                }
    
    
                }
    
                catch ( Exception ex )
                {
                // Note:  No exception seen - Just Visual Studio 2015 "An unhandled exception occurred" dialog.
                    throw;
                }
                return new ScanResult
                {
                    Text = "",
                };
            }
    
        }
    
  • Vinod.5653Vinod.5653 USMember
    edited September 2015

    does anybody know how to capture image after scanning the barcode or qrcode using MobileBarcodeScanner? I am getting the proper scanned barcode or qrcode in text format. But can I get the scanned image from it?
    Following is my code :

    async private void startScanning()
        {
            scanner.UseCustomOverlay = false;
            scanner.UseCustomOverlay = false;
    
            scanner.TopText = "Hold camera up to QR code or barcode";
            scanner.BottomText = "Camera will automatically scan QR code/Barcode \r\n\rPress the 'Back' button to cancel";
            await scanner.Scan().ContinueWith(t =>
            {
    
                if (t.Result != null)
                    processResult(t.Result);
            });
        }
    
    private void processResult(ZXing.Result result)
        {
            if ((result != null) && !string.IsNullOrEmpty(result.Text))
            {
                string qrCode = result.Text;
    

    // Now I thought result.RawBytes could help something in generating an image but its giving me null

                byte[] points = result.RawBytes;
    
                if (points != null)
                {
                    Debug.WriteLine("raw bytes.");
                    foreach (byte r in points)
                        Debug.WriteLine(r);
                }
                else
                    Debug.WriteLine("No raw bytes");
    
                //this.Dispatcher.BeginInvoke(() =>
                //{
                //    scanner.Cancel();
                //    scanResultDialog = new CustomMessageBox();
                //    scanResultDialog.VerticalAlignment = VerticalAlignment.Center;
                //    scanResultDialog.Content = new ScanResultBox(qrCode);
                //    scanResultDialog.Show();
                //});
            }
            else
            {
                MessageBox.Show("failed");
            }
        }
    

    Please help..

  • stevehawkinsstevehawkins GBMember

    having issues reading a pdf417 on a samsung active tab in android (4.4).

    tried several settings and no joy picking up the barcode at all.

    current code:

    var options = new ZXing.Mobile.MobileBarcodeScanningOptions();
    options.PossibleFormats = new List<ZXing.BarcodeFormat>() { BarcodeFormat.PDF_417,
    BarcodeFormat.DATA_MATRIX, BarcodeFormat.QR_CODE};

                options.TryHarder = true;
    
    
                var result = await scanner.Scan(options);
    

    any help would be appreciated

  • ASyedASyed USMember ✭✭

    @Redth

    Hi Jonathan, I am trying to use, Zxing in Xamarin iOS app and want to use small view to scan the barcode instead of complete new view. is it possible ??

  • sid12sid12 INMember ✭✭

    I have install 'ZXing.Net.Mobile' package but still I am not able to create 'ZXingScannerPage' page instance in my page.
    Why?
    please help.

  • vinukodivinukodi Member ✭✭
    edited December 2019

    Hi,
    I'm using Zebra TC56 device, I have installed my app in it. I wan't to use hard button(integrated scanner) to scan the barcode, and process the scanned value before it set to the field.

    Is there any called scanComplete event to know the scan got complete before it sets the value to respective textbox/entry?

Sign In or Register to comment.