ZXing.Net.Mobile: Android - first scan never works, works only after permissions are given.
I’m running into this exact same issue as this on 2.4.1.
Here’s my scanning page
public class BarcodeScanningPage : ContentPage
{
ZXingScannerView ZXingView { get; set; }
ZXingDefaultOverlay Overlay { get; set; }
public BarcodeScanningPage() : base()
{
Title = "Scanning...";
ZXingView = new ZXingScannerView
{
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand,
AutomationId = "zxingScannerView",
Options = new ZXing.Mobile.MobileBarcodeScanningOptions()
{
PossibleFormats = new List<ZXing.BarcodeFormat>() {
ZXing.BarcodeFormat.CODE_39, ZXing.BarcodeFormat.QR_CODE
}
}
};
ZXingView.OnScanResult += (result) => Device.BeginInvokeOnMainThread(async () =>
{
// Stop analysis until we navigate away so we don't keep reading barcodes
ZXingView.IsAnalyzing = false;
await NavigationHelper.PushAsync(new SearchResultsPage(new ApiModels.SearchItemsParams()
{
Keyword = result.Text,
ResultsPerPage = App.AppConfig.SearchResultsPerPage
}, result.Text, true));
//await NavigationHelper.PopAsync();
});
Overlay = new ZXingDefaultOverlay()
{
BottomText = "Scan Barcodes or QR Codes",
ShowFlashButton = ZXingView.HasTorch,
AutomationId = "zxingDefaultOverlay",
};
Overlay.FlashButtonClicked += (sender, e) =>
{
ZXingView.IsTorchOn = !ZXingView.IsTorchOn;
};
var grid = new Grid()
{
VerticalOptions = LayoutOptions.FillAndExpand,
HorizontalOptions = LayoutOptions.FillAndExpand,
};
grid.Children.Add(ZXingView);
grid.Children.Add(Overlay);
// The root page of your application
Content = grid;
}
protected override void OnAppearing()
{
base.OnAppearing();
ZXingView.IsScanning = true;
}
protected override void OnDisappearing()
{
ZXingView.IsScanning = false;
base.OnDisappearing();
}
}
Any ideas how I might get around this? Thanks! Great plugin.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 6
- Comments: 18 (1 by maintainers)
Hi guys, this isn’t a fix but instead a work around.
If you use James Montemagno’s permission library to check for permissions before you present your scanner, the android device will scan on first time load.
I’m not familiar with Forms but Android needed the following code in my Activity. I’m running
2.4.1.Download version 2.3.1, it works fine to me. This is an old bug, but was fixed with 2.3.1 .However it seems to happen again in latest 2.4.1 …
Upgrading to the
3.0.0-beta5resolved the issue to me. ThanksI am running into this issue as well across all Android devices with the latest version. Any possible workarounds?