首页 > 解决方案 > ZXING 手机重复扫描问题

问题描述

我正在使用 zing 移动扫描仪,它运行良好,但是我从不同的按钮调用相同的操作,它拒绝扫描它会打开预览窗口,但不会调用扫描。

public async  void  BtnScanStockTakeItem_Clicked(object sender, EventArgs e)
{    

     var scanPage = new ZXingScannerPage();
     scanPage.ToggleTorch();
     scanPage.IsScanning = true;               
     await Navigation.PushAsync(scanPage);
     scanPage.OnScanResult += (result) =>
     {


      // Stop scanning
      scanPage.IsScanning = false;

      // Pop the page and show the result
      Device.BeginInvokeOnMainThread(async () =>
    {
        await Navigation.PopAsync();
    }
}

然后我从另一个按钮方法调用上面的方法让我们说保存的功能

private async void SaveFunction(object sender, EventArgs e)
{

        foreach (var item in transferList)
        {

            int z = await restServices.PostStockTakeTransaction(item);
        }
        Preferences.Set("StockTakeWarehouse", pickStockTake.SelectedIndex);
        WarehouseName = pickStockTake.SelectedItem.ToString();
        bool x = await DisplayAlert("Test", "Item Saved", "ReScan", "Cancel");
        if (x)
        {
             BtnScanStockTakeItem_Clicked(sender, e);
            //this is where it rescans the item
        }
 }

字符串的事情是我没有收到任何 logcat 错误或扫描仪的视口没有显示,但由于某些原因与以前相同的条形码格式不接受扫描。

标签: xamarin.forms

解决方案


对于其他面临类似问题的人来说,这是我的相机线程没有正确调用的事实,我必须这样做

 Device.BeginInvokeOnMainThread(async () =>
 {
      BtnScanStockTakeItem_Clicked(sender, e);
 });

按预期工作


推荐阅读