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.
I am running into this issue as well across all Android devices with the latest version. Any possible workarounds?
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 ...
This issue is happening for me, the exact same code works on iOS perfectly!
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.
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.
This work around didn't work for me.
Using 2.3.1 instead of 2.4.1 worked for me 🤷♂️
As MKuckert mentioned - Using 2.3.1 instead of 2.4.1 worked.
I solved using James Montemagno's permission library in the 'onClick' button that go to scan class (not into the 'scan class' itself)
If user give permission then I go to scan class else I give error message
(sorry for bad english)
Reverting to ZXing.Net.Mobile 2.3.2 and ZXing.Net.Mobile.Forms 2.3.2 resolved the problem for me.
I'm not familiar with Forms but Android needed the following code in my Activity. I'm running 2.4.1.
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults)
{
base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
ZXing.Net.Mobile.Android.PermissionsHandler.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}
@zlannin The issue we are talking about is when using this in Xamarin Forms, you put this code into your MainActivity, and it never asks for your permissions and the camera never loads.
I have that code in my app and log when it triggers, it has never once triggered (other than the one time testing writing to my log file) over the 6 week development cycle of the app I was using the library in.
I tried what @TonyC5 says.
In MainActivity it works like this.
Works!!!!
`
protected override void OnCreate(Bundle bundle)
{
instance = this;
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(bundle);
global::Xamarin.Forms.Forms.Init(this, bundle);
global::ZXing.Net.Mobile.Forms.Android.Platform.Init();
LoadApplication(new App());
}
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Permission[] grantResults)
{
global::ZXing.Net.Mobile.Android.PermissionsHandler.OnRequestPermissionsResult(requestCode, permissions, grantResults);
PermissionsImplementation.Current.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}`
Overriding OnRequestPermissionsResult in my Activity did not work for me in 2.4.1
Thanks for reporting this issue! Unforunately it took me way too long to respond 😭. Sorry, I apologize! Recently the source code for this project was completely refactored to modernize it. Many PR's were included in this effort, and many bugs were hopefully fixed. Please try out the latest 3.x series of NuGet packages (currently in prerelease). To try and make the project more maintainable in my spare time going forward, I've decided to close all existing issues to start with a clean slate. If you're still experiencing this issue on the newest version, please open a new issue with as much detail as possible. Thank you for your patience and understanding! Happy scanning!
Upgrading to the 3.0.0-beta5 resolved the issue to me. Thanks
I think if you check permission before Push the scan page you can prevent this problem :) Say the client have to give permission before the scan page appear
@Redth By when 3.x(pre-release) version will be production ready?
Most helpful comment
I'm not familiar with Forms but Android needed the following code in my Activity. I'm running
2.4.1.