2

我在 Xamarin 表单中使用 qr 代码扫描仪。插件是 Zxing.net.mobile。我想连续扫描,为此我写了一个代码。它在 IOS 中工作,但在 android 中它不工作。实际上这个过程是首先用户将扫描一个二维码,他会得到他的结果,然后他会看到一个弹出窗口“你想继续吗”。他单击“是”,扫描仪应该重新启动。但是该页面在android中被击中。你能帮我解决这个问题吗?

private async Task Scanner_OnScanResultAsync(ZXing.Result result)
    {

        Device.BeginInvokeOnMainThread(async () =>
        {
        string password = App.LoggedInUser.Password;

        scanner.IsScanning = false;

            App.ScannedResult = result.Text;
            //  await DisplayAlert("Scanned Qrcode", result.Text, "OK");
            if (!(App.ScannedResult.StartsWith("MSS") && App.ScannedResult.Length == 10))
            {
                await DisplayAlert("", "It's a Invalid QRCode", "Okay");
                await Navigation.PushAsync(new DashboadPages.DashboardPage());
            }
            else
            {
                try
                {
                    details = await hs.GetDeviceByQRCode(App.LoggedInUser.LoginId, password, result.Text);
                    if (details.Details == null && details.Created == null && details.History == null)
                    {
                        await Navigation.PushPopupAsync(new MacIdPopUpPage(DeviceMacIDChange, DeviceIdentifier)); // popUp    
                    }
                    else
                    {
                        await DisplayAlert("Error", "This QR Code is associated with an existing item in MINT", "Okay");
                        await Navigation.PopToRootAsync();
                    }
                }
                catch (Exception ex)
                {
                    await DisplayAlert("", ex.Message, "");
                }
            }
        });
    }


    public async void DeviceMacIDChange(object sender, string deviceIdentifier)
    {
        ItemDetail.DeviceIdentifier = deviceIdentifier; // updating macId

        var item = new GenericInputModel
        {
            HubbleId = App.LoggedInUser.LoginId,
            DisplayName = App.LoggedInUser.FName,
            Password = App.LoggedInUser.Password,
            UpdationInfo = new UpdationInfoModel
            {
                ItemDetail = ItemDetail
            }
        };
        var response = await hs.UpdateDeviceDetails(item, details.Id);
        if (response.Message == "Document has been updated successfully")
        {

            await DisplayAlert("Success", $"Your Item {item.UpdationInfo.ItemDetail.ItemName} has been saved to inventory", "Okay");
        }
        else
        {
            await DisplayAlert("Failed", response.Message, "Okay");
        }
        bool yes = await DisplayAlert("Do you want to continue scanning?", "", "Continue", "Exit");
        if (yes)
        {
            scanner.IsScanning = true;
        }
        else
        {
            await App.RefreshDataAsync();
            await Navigation.PopToRootAsync(); // Exit
        }

    }
4

0 回答 0