Absolutelly stuck with Zxing barcode scanner

JosuGJosuG ESMember ✭✭

Hello:

I have downloaded via NuGet the Zxing bar code scanner and my app is crashing while reading the barcode. My code is:

protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            MobileBarcodeScanner.Initialize(Application);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            ImageButton botonScan = FindViewById<ImageButton>(Resource.Id.bScan);
            botonScan.Click += async (sender, e) =>
          {
              ZXing.Result result;
              var scanner = new ZXing.Mobile.MobileBarcodeScanner()
              {
                  UseCustomOverlay = false,
                  TopText = "Hold camera up to barcode to scan",
                  BottomText = "Barcode will automatically scan"
              };
              scanner.AutoFocus();
              result = await scanner.Scan();

              Toast.MakeText(this,result.Text, ToastLength.Short).Show();

          };

            }

It crashes both, while debugging (without throwing error) and while testing in device

What I am doing wrong?

Sorry if repost, I wrote this lines before but I am unnable to find the post

Posts

  • JosuGJosuG ESMember ✭✭
    edited March 2017

    Got solved, changed event in the following way

    botonScan.Click += (sender, e) =>
              {
                  Negocio.Elemento _elemento = new Negocio.Elemento();
                  Negocio.CodigosBarras _codigo = new Negocio.CodigosBarras();
    
    
    
                  var scanner = new ZXing.Mobile.MobileBarcodeScanner()
                  {
                      UseCustomOverlay = false,
                      TopText = "Hold camera up to barcode to scan",
                      BottomText = "Barcode will automatically scan"
                  };
    
    
    
                  try
                  {
                      scanner.Scan().ContinueWith(t =>
                      RunOnUiThread(
        () =>
        {
    
            var result = t.Result;
    
                          Toast.MakeText(this, result.Text, ToastLength.Short).Show();
                      }));
    
  • Hi, I´m facing a problem using ZXing QR Code reader component, my problem is:

    I need to use QR code reader on two different pages, one for login validation and another for opening documents through QR code identification, the first page works fine but the second page camera get static, even if I try to change the IsScanning property to true on the OnAppearing or the constructor of the second page, I tried to instantiate the ZXing component on the second page and did´t work, does anyone have any sugestions for this problem?

  • JosuGJosuG ESMember ✭✭

    Can you post the code used for initialization in both forms?

Sign In or Register to comment.