Xamarin Android Qr问题(继续扫描)

时间:2018-03-08 13:43:10

标签: android xamarin.forms zxing.net

我在Xamarin表单中使用qr代码扫描程序。插件是Zxing.net.mobile。我想连续扫描,因为我写了一个代码。它在IOS工作但在android中却无法正常工作。实际上,这个过程是第一个用户将扫描一个二维码,他将得到他的结果,然后他将显示一个弹出窗口"你想继续吗?#34;。他点击了#34;是",扫描仪应该重新开始。但该页面在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
        }

    }

0 个答案:

没有答案