在Xamarin Android中使用Zxing扫描仪获取以前的扫描结果或错误的扫描结果

时间:2018-12-09 10:24:24

标签: xamarin.android zxing.net

  

Blockquote

我从扫描仪中得到了一些“ Hello :)”结果,或者在大多数情况下是前一次扫描结果。假设我成功扫描了“ ABC001”,然后尝试扫描“ XYZ001”,但是结果是“ ABC001”,即先前的扫描结果。 我在下面分享了我的代码。请有人告诉我我在哪里做错了。我正在使用NuGet的ZXing.Net.Mobile的最新版本2.4.1。谢谢

  

Blockquote

    private MobileBarcodeScanner scanner;

    private void StartScanning()
    {
        // Starting the inbuilt scanner to scann

        View zxingOverlay;
        MobileBarcodeScanner.Initialize(Application);
        scanner = new MobileBarcodeScanner();
        //Inflate our custom overlay from a resource layout
        zxingOverlay = LayoutInflater.FromContext(this).Inflate(Resource.Layout.ScannerOverlay, null);
        //Find the button from our resource layout and wire up the click event
        var flashButton = zxingOverlay.FindViewById<Button>(Resource.Id.buttonZxingFlash);
        flashButton.Click += (sender, e) => scanner.ToggleTorch();
        scanner.UseCustomOverlay = true;
        //Inflate our custom overlay from a resource layout
        //Set our custom overlay
        scanner.CustomOverlay = zxingOverlay;
        //We can customize the top and bottom text of the default overlay
        scanner.TopText = "Hold the camera up to the barcode\nAbout 6 inches away";
        scanner.BottomText = "Wait for the barcode to automatically scan!";
        var opt = new MobileBarcodeScanningOptions();
        opt.DelayBetweenContinuousScans = 3000;
        //Start scanning
        scanner.ScanContinuously(opt, HandleScanResult);
    }

     /*
    * Handle the scanned Result
    */
    private void HandleScanResult(ZXing.Result result)
    {

        if (!string.IsNullOrEmpty(result.Text))
        {
           this.RunOnUiThread(() => Toast.MakeText(this, result.Text), ToastLength.Short).Show());
        }
        else
        {
            this.RunOnUiThread(() => Toast.MakeText(this, "scanning failed"), ToastLength.Short).Show());
        }
    }

0 个答案:

没有答案
相关问题