Reputation: 3494
I am using Zxing barcode scanner in my PCL in Xamarin Form. The Issue is flashlight ON/Off option is not displaying on UI. This is very important for me to provide this option to the user.
zxing = new ZXingScannerView
{
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.FillAndExpand,
HeightRequest = 400,
AutomationId = "zxingScannerView",
IsTorchOn = true,
};
string _BarCode = "";
int _CountItems = 0;
int _scannedItem = 0;
zxing.OnScanResult += (result) =>
Device.BeginInvokeOnMainThread(async () =>
{
// doing something that i want with scan result
});
overlay = new ZXingDefaultOverlay
{
ShowFlashButton = true,
AutomationId = "zxingDefaultOverlay",
};
overlay.HeightRequest = 2;
overlay.BindingContext = this;
overlay.FlashButtonClicked += (sender, e) =>
{
zxing.IsTorchOn = !zxing.IsTorchOn;
};
In Assambly info i have already added this line of code
[assembly: UsesPermission(Android.Manifest.Permission.Flashlight)]
Can you please tell me what mistake i did in my code. Thanks for comments and suggestions
Upvotes: 1
Views: 1924
Reputation: 141
In a scan button ...
var overlay = new ZXingDefaultOverlay
{
ShowFlashButton = true,
TopText = "Please scan the barcode...",
BottomText = string.Empty
};
overlay.BindingContext = overlay;
var scan = new ZXingScannerPage(null, overlay);
await Navigation.PushAsync(scan);
overlay.FlashButtonClicked += (s, ed) =>
{
scan.ToggleTorch();
};
scan.OnScanResult += (result) =>
{
Device.BeginInvokeOnMainThread(async () =>
{
await Navigation.PopAsync();
var _scanResult = result.Text;
});
};
Upvotes: 3