I'm trying to scan a QR Code from my Xamarin.Forms application but the QR Code isn't getting detected until i restart the scanner.
I'm using ZXing.Net.Mobile.Forms. Once the ScannerPage
has been pushed on the navigation stack it requests the camera permissions. After fulfilling the request it has access to the camera but isn't scanning the QR Code. I tried changing the permission handler since it works after restarting the scanner after granting the permission, but that didn't work.
private async void createScanPageAsync()
{
#if __ANDROID__
// Initialize the scanner first so it can track the current context
MobileBarcodeScanner.Initialize (Application);
#endif
var options = new MobileBarcodeScanningOptions()
{
TryHarder = true,
};
var scanPage = new ZXingScannerPage()
{
Title = AppResources.scanPageTitle,
DefaultOverlayTopText = AppResources.scanPageTitle,
DefaultOverlayShowFlashButton = true
};
await Navigation.PushAsync(scanPage);
scanPage.OnScanResult += (scanResult) =>
{
scanPage.IsScanning = false;
Vibration.Vibrate();
QRCode scans = JsonConvert.DeserializeObject<QRCode>(scanResult.Text);
AppPreferences.Network.Ip = scans.ip;
AppPreferences.Network.Port = scans.port;
Device.BeginInvokeOnMainThread(async () =>
{
await Navigation.PopAsync();
});
};
}
}
The expected outcome would be a successful scan on the first try, but i only get a successful scan after granting permissions and then reopening the scanner page.