Android - first scan never works, works only after permissions are given.
See original GitHub issueI’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.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:6
- Comments:18 (1 by maintainers)
Top Results From Across the Web
Android 10 not working with BLE Bluetooth scanning
To make BLE scanning work on Android apps targeting Android 10 you need to ask the user for. ACCESS_BACKGROUND_LOCATION.
Read more >Bluetooth permissions
Quickly bring your app to life with less code, using a modern declarative approach to UI, and the simplicity of Kotlin. ... Start...
Read more >Android permissions - BLE - Android 12
When I try to run the app, I get a runtime error: Need android.permission.BLUETOOTH_SCAN permission for android.content.
Read more >Change app permissions on your Android phone
Some of these steps work only on Android 11 and up. ... Allow only while using the app: The app can use the...
Read more >Making Android BLE work — part 1
Scanning only works if you have the following permission AND you have Location Service activated. <uses-permission android:name="android.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

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.