protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); MobileBarcodeScanner.Initialize(Application); // Set our view from the "main" layout resource SetContentView(Resource.Layout.home); TextView textView = FindViewById <TextView>(Resource.Id.text); textView.Text = "Message"; scanner = new MobileBarcodeScanner(); textView.Click += (o, e) => { scanner.UseCustomOverlay = false; //We can customize the top and bottom text of the default overlay scanner.TopText = "Hold the camera up to the barcode\nAbout 6 inches away"; scanner.BottomText = "Wait for the barcode to automatically scan!"; var opt = new MobileBarcodeScanningOptions(); opt.DelayBetweenContinuousScans = 3000; //Start scanning scanner.ScanContinuously(opt, HandleScanResult); // var intent = new Intent(this, typeof(BarCodeScanner)); //intent.AddFlags(ActivityFlags.ClearTop); //intent.AddFlags(ActivityFlags.ClearTask); //intent.AddFlags(ActivityFlags.NewTask); // StartActivity(intent); //Finish(); }; }
private void StartScanning(AppTask thisTask) { currentScanTask = thisTask; scanner = new MobileBarcodeScanner(NavigationController) { UseCustomOverlay = false, TopText = thisTask.TaskType.Description, BottomText = thisTask.Description }; scanner.ScanContinuously(HandleScanResult); }
private async void HandleScanResult(ZXing.Result result) { if (result == null) { return; } _player.Start(); var lookupResult = await Http.GetAssetName(result.Text); lookupResult = lookupResult.Replace("\"", ""); RunOnUiThread(() => { if (_scannedItems.Contains(lookupResult)) { _scanner.Cancel(); var alert = new AlertDialog.Builder(this); alert.SetTitle("Duplicate Scan"); alert.SetMessage($"Are you sure you want to scan {lookupResult} again?"); alert.SetPositiveButton("Yes", (senderAlert, args) => { _scannedItems.Add(lookupResult); UpdateScanListView(); _scanner.ScanContinuously(_option, HandleScanResult); }); alert.SetNegativeButton("No", (senderAlert, args) => { _scanner.ScanContinuously(_option, HandleScanResult); }); Dialog dialog = alert.Create(); dialog.Show(); } else { _scannedItems.Add(lookupResult); UpdateScanListView(); } }); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); Xamarin.Essentials.Platform.Init(this, savedInstanceState); MobileBarcodeScanner.Initialize(Application); scanner = new MobileBarcodeScanner(); SetContentView(Resource.Layout.activity_main); Android.Support.V7.Widget.Toolbar toolbar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar); SetSupportActionBar(toolbar); this.btnPair = FindViewById <Button>(Resource.Id.main_pair_button); btnPair.Click += async delegate { btnPair.Background = this.Resources.GetDrawable(Resource.Drawable.gradient); btnPair.RefreshDrawableState(); scanner.UseCustomOverlay = false; scanner.TopText = this.Resources.GetString(Resource.String.pair_top_text); scanner.BottomText = this.Resources.GetString(Resource.String.pair_bottom_text); var result = await scanner.Scan(); this.HandlePairResult(result); }; this.btnScan = FindViewById <Button>(Resource.Id.main_scan_button); btnScan.Click += delegate { btnScan.Background = this.Resources.GetDrawable(Resource.Drawable.gradient); btnScan.RefreshDrawableState(); scanner.UseCustomOverlay = false; scanner.TopText = this.Resources.GetString(Resource.String.scan_top_text); scanner.BottomText = this.Resources.GetString(Resource.String.scan_bottom_text); var opt = new MobileBarcodeScanningOptions() { DelayBetweenContinuousScans = 1000, AutoRotate = false }; scanner.ScanContinuously(opt, HandleScanResult); }; this.chkSound = FindViewById <CheckBox>(Resource.Id.main_sound_checkbox); this.chkSound.CheckedChange += delegate { this.skbVolume.Enabled = this.chkSound.Checked; }; this.skbVolume = FindViewById <SeekBar>(Resource.Id.main_volume_seekbar); }
public void ScanProduct() { var opt = new MobileBarcodeScanningOptions(); opt.DelayBetweenContinuousScans = 3000; // Reset scanner ScanStatus(false); scanner.Torch(false); torchFab.SetImageDrawable(ContextCompat.GetDrawable(Activity, Resource.Drawable.ic_flash_on_white_24dp)); // Start scanning scanner.ScanContinuously(opt, HandleScanResult); }
private void LaunchScanner(object sender, EventArgs e) { MobileBarcodeScanner.Initialize(Application); _scanner = new MobileBarcodeScanner { FlashButtonText = "Flash", TopText = "Hold camera up to barcode to scan", BottomText = "Barcode will automatically scan" }; _option = new MobileBarcodeScanningOptions { DelayBetweenContinuousScans = 1000 }; _scanner.ScanContinuously(_option, HandleScanResult); }
public void ScanContinuously(Action <string> onRead, Action onError = null) { scanner.ScanContinuously(options, result => { if (result == null || string.IsNullOrEmpty(result?.Text)) { if (onError != null) { onError(); } } else { onRead(result.Text); } }); }
void BtnContScan_TouchUpInside(object sender, EventArgs e) { try { //Tell our scanner to use the default overlay //Tell our scanner to use the default overlay scanner.UseCustomOverlay = false; var opt = new MobileBarcodeScanningOptions(); opt.DelayBetweenContinuousScans = 3000; //Start scanning scanner.ScanContinuously(opt, HandleScanResult); } catch (Exception ex) { npcc_services.inf_mobile_exception_managerAsync(ex.Message); } }
void Scan_Clicked(object sender, EventArgs e) { #if __ANDROID__ MobileBarcodeScanner.Initialize(Application); #endif viewModel.Text = ""; viewModel.Transmission = new Message(); Action <Result> Handler = new Action <Result>(ScanHandler); viewModel.Transmission.OnMessageCompleted += CancelScanning; Scanner = new MobileBarcodeScanner(); MobileBarcodeScanningOptions Options = new MobileBarcodeScanningOptions() { DelayBetweenAnalyzingFrames = 50, DelayBetweenContinuousScans = 50 }; Scanner.ScanContinuously(Options, Handler); }
private void buttonScanContinuously_Click(object sender, RoutedEventArgs e) { //Tell our scanner to use the default overlay scanner.UseCustomOverlay = false; //We can customize the top and bottom text of our default overlay scanner.TopText = "Hold camera up to barcode"; scanner.BottomText = "Camera will automatically scan barcode\r\n\r\nPress the 'Back' button to Cancel"; //Start scanning scanner.ScanContinuously(async(result) => { var msg = "Found Barcode: " + result.Text; await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() => { await MessageBox(msg); }); }); }
private void buttonScanContinuously_Click(object sender, RoutedEventArgs e) { //Tell our scanner to use the default overlay scanner.UseCustomOverlay = false; //We can customize the top and bottom text of our default overlay scanner.TopText = "Hold camera up to barcode"; scanner.BottomText = "Camera will automatically scan barcode\r\n\r\nPress the 'Back' button to Cancel"; //Start scanning scanner.ScanContinuously(result => { var msg = "Found Barcode: " + result.Text; this.Dispatcher.BeginInvoke(() => { MessageBox.Show(msg); }); }); }
public async Task StartScan(MobileBarcodeScanningOptions options = null) { try { var scanner = new MobileBarcodeScanner() { TopText = "Scan Code" }; scanner.ScanContinuously(options ?? new MobileBarcodeScanningOptions { PossibleFormats = new List <BarcodeFormat> { BarcodeFormat.EAN_8, BarcodeFormat.EAN_13, BarcodeFormat.CODE_39, BarcodeFormat.CODE_128, BarcodeFormat.QR_CODE }, AutoRotate = false, UseFrontCameraIfAvailable = false, TryHarder = true }, (result) => { CrossSimpleAudioPlayer.Current.Load("beep.wav"); CrossSimpleAudioPlayer.Current.Play(); OnScanned?.Invoke(this, result.Text); MessagingCenter.Send(this, MessageKey.BARCODE_SCANNED, result.Text); }); Device.StartTimer(TimeSpan.FromSeconds(3), () => { scanner.AutoFocus(); return(true); }); } catch (Exception ex) { await Application.Current.MainPage.DisplayAlert(TranslateExtension.GetValue("alert_title_error"), ex.Message, TranslateExtension.GetValue("alert_message_ok")); } }
public async Task StartScan(bool useFrontCamera = false, MobileBarcodeScanningOptions options = null) { try { var scanner = new MobileBarcodeScanner() { TopText = "Scan Code" }; scanner.ScanContinuously(options ?? new MobileBarcodeScanningOptions { PossibleFormats = new List <BarcodeFormat> { BarcodeFormat.EAN_8, BarcodeFormat.EAN_13, BarcodeFormat.CODE_39, BarcodeFormat.CODE_128, BarcodeFormat.QR_CODE }, AutoRotate = false, UseFrontCameraIfAvailable = useFrontCamera, TryHarder = true, DisableAutofocus = false }, (result) => { BarcodeScanned?.Invoke(this, result.Text); MessagingCenter.Send(this, Constants.BARCODE_SCANNED, result.Text); }); Device.StartTimer(TimeSpan.FromSeconds(3), () => { scanner.AutoFocus(); return(true); }); } catch (Exception ex) { await Application.Current.MainPage.DisplayAlert("Error", ex.Message, "Ok"); } }
private void BtnMulty_Click(object sender, EventArgs e) { //Tell our scanner we want to use a custom overlay instead of the default scanner.UseCustomOverlay = true; //Inflate our custom overlay from a resource layout zxingOverlay = LayoutInflater.FromContext(this).Inflate(Resource.Layout.ZxingOverlay, null); //Find the button from our resource layout and wire up the click event flashButton = zxingOverlay.FindViewById <Button>(Resource.Id.buttonZxingFlash); flashButton.Click += FlashButton_Click; //Set our custom overlay scanner.CustomOverlay = zxingOverlay; var opt = new MobileBarcodeScanningOptions(); opt.DelayBetweenContinuousScans = 3000; //Start scanning scanner.ScanContinuously(opt, HandleScanResult); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); Xamarin.Essentials.Platform.Init(Application); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); //Create a new instance of our Scanner scanner = new MobileBarcodeScanner(); buttonScanDefaultView = this.FindViewById <Button>(Resource.Id.buttonScanDefaultView); buttonScanDefaultView.Click += async delegate { //Tell our scanner to use the default overlay scanner.UseCustomOverlay = false; //We can customize the top and bottom text of the default overlay scanner.TopText = "Hold the camera up to the barcode\nAbout 6 inches away"; scanner.BottomText = "Wait for the barcode to automatically scan!"; //Start scanning var result = await scanner.Scan(); HandleScanResult(result); }; buttonContinuousScan = FindViewById <Button>(Resource.Id.buttonScanContinuous); buttonContinuousScan.Click += delegate { scanner.UseCustomOverlay = false; //We can customize the top and bottom text of the default overlay scanner.TopText = "Hold the camera up to the barcode\nAbout 6 inches away"; scanner.BottomText = "Wait for the barcode to automatically scan!"; var opt = new MobileBarcodeScanningOptions(); opt.DelayBetweenContinuousScans = 3000; //Start scanning scanner.ScanContinuously(opt, HandleScanResult); }; Button flashButton; View zxingOverlay; buttonScanCustomView = this.FindViewById <Button>(Resource.Id.buttonScanCustomView); buttonScanCustomView.Click += async delegate { //Tell our scanner we want to use a custom overlay instead of the default scanner.UseCustomOverlay = true; //Inflate our custom overlay from a resource layout zxingOverlay = LayoutInflater.FromContext(this).Inflate(Resource.Layout.ZxingOverlay, null); //Find the button from our resource layout and wire up the click event flashButton = zxingOverlay.FindViewById <Button>(Resource.Id.buttonZxingFlash); flashButton.Click += (sender, e) => scanner.ToggleTorch(); //Set our custom overlay scanner.CustomOverlay = zxingOverlay; scanner.UseCustomOverlay = true; //Start scanning! var result = await scanner.Scan(new MobileBarcodeScanningOptions { AutoRotate = true }); HandleScanResult(result); }; buttonScanCustomAreaView = this.FindViewById <Button>(Resource.Id.buttonScanCustomAreaView); buttonScanCustomAreaView.Click += async delegate { //Tell our scanner we want to use a custom overlay instead of the default scanner.UseCustomOverlay = true; //Inflate our custom overlay from a resource layout zxingOverlay = LayoutInflater.FromContext(this).Inflate(Resource.Layout.ZxingOverlayCustomScanArea, null); scanArea = zxingOverlay.FindViewById <View>(Resource.Id.scanView); //Find all the buttons and wire up their events buttonRectangle = zxingOverlay.FindViewById <Button>(Resource.Id.buttonSquareScanRectangle); buttonSquare = zxingOverlay.FindViewById <Button>(Resource.Id.buttonSquareScanView); scanViewPosition = zxingOverlay.FindViewById <ToggleButton>(Resource.Id.toggleButtonScanViewLocation); buttonIncrease = zxingOverlay.FindViewById <ImageButton>(Resource.Id.buttonIncrease); buttonDecrease = zxingOverlay.FindViewById <ImageButton>(Resource.Id.buttonDecrease); buttonRandom = zxingOverlay.FindViewById <Button>(Resource.Id.buttonRandom); buttonRectangle.Click += Rectangle_Click; buttonSquare.Click += Square_Click; scanViewPosition.Click += ScanViewPosition_Click; buttonIncrease.Click += ButtonIncrease_Click; buttonDecrease.Click += ButtonDecrease_Click; buttonRandom.Click += ButtonRandom_Click; //Set our custom overlay and custom scan area scanner.CustomOverlay = zxingOverlay; scanner.UseCustomOverlay = true; scanner.CustomOverlayScanAreaView = scanArea; //Start scanning! var result = await scanner.Scan(new MobileBarcodeScanningOptions { AutoRotate = true }); HandleScanResult(result); }; buttonFragmentScanner = FindViewById <Button>(Resource.Id.buttonFragment); buttonFragmentScanner.Click += delegate { StartActivity(typeof(FragmentActivity)); }; buttonFragmentScannerCustomArea = FindViewById <Button>(Resource.Id.buttonFragmentCustomArea); buttonFragmentScannerCustomArea.Click += delegate { StartActivityForResult(typeof(FragmentActivityCustomScanArea), FRAGMENT_SCAN_REQUEST); }; buttonGenerate = FindViewById <Button>(Resource.Id.buttonGenerate); buttonGenerate.Click += delegate { StartActivity(typeof(ImageActivity)); }; }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Initialize the scanner first so we can track the current context MobileBarcodeScanner.Initialize(Application); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); //Create a new instance of our Scanner scanner = new MobileBarcodeScanner(); buttonScanDefaultView = this.FindViewById <Button>(Resource.Id.buttonScanDefaultView); buttonScanDefaultView.Click += async delegate { //Tell our scanner to use the default overlay scanner.UseCustomOverlay = false; //We can customize the top and bottom text of the default overlay scanner.TopText = "Hold the camera up to the barcode\nAbout 6 inches away"; scanner.BottomText = "Wait for the barcode to automatically scan!"; //Start scanning var result = await scanner.Scan(); HandleScanResult(result); }; buttonContinuousScan = FindViewById <Button> (Resource.Id.buttonScanContinuous); buttonContinuousScan.Click += delegate { scanner.UseCustomOverlay = false; //We can customize the top and bottom text of the default overlay scanner.TopText = "Hold the camera up to the barcode\nAbout 6 inches away"; scanner.BottomText = "Wait for the barcode to automatically scan!"; var opt = new MobileBarcodeScanningOptions(); opt.DelayBetweenContinuousScans = 3000; //Start scanning scanner.ScanContinuously(opt, HandleScanResult); }; Button flashButton; View zxingOverlay; buttonScanCustomView = this.FindViewById <Button>(Resource.Id.buttonScanCustomView); buttonScanCustomView.Click += async delegate { //Tell our scanner we want to use a custom overlay instead of the default scanner.UseCustomOverlay = true; //Inflate our custom overlay from a resource layout zxingOverlay = LayoutInflater.FromContext(this).Inflate(Resource.Layout.ZxingOverlay, null); //Find the button from our resource layout and wire up the click event flashButton = zxingOverlay.FindViewById <Button>(Resource.Id.buttonZxingFlash); flashButton.Click += (sender, e) => scanner.ToggleTorch(); //Set our custom overlay scanner.CustomOverlay = zxingOverlay; //Start scanning! var result = await scanner.Scan(); HandleScanResult(result); }; buttonFragmentScanner = FindViewById <Button> (Resource.Id.buttonFragment); buttonFragmentScanner.Click += delegate { StartActivity(typeof(FragmentActivity)); }; buttonGenerate = FindViewById <Button> (Resource.Id.buttonGenerate); buttonGenerate.Click += delegate { StartActivity(typeof(ImageActivity)); }; }
public override void ViewDidLoad() { //Create a new instance of our scanner scanner = new MobileBarcodeScanner(this.NavigationController); Root = new RootElement("ZXing.Net.Mobile") { new Section { new StyledStringElement("Scan with Default View", async() => { //Tell our scanner to use the default overlay scanner.UseCustomOverlay = false; //We can customize the top and bottom text of the default overlay scanner.TopText = "Hold camera up to barcode to scan"; scanner.BottomText = "Barcode will automatically scan"; //Start scanning var result = await scanner.Scan(); HandleScanResult(result); }), new StyledStringElement("Scan Continuously", () => { //Tell our scanner to use the default overlay scanner.UseCustomOverlay = false; //Tell our scanner to use our custom overlay scanner.UseCustomOverlay = true; scanner.CustomOverlay = customOverlay; var opt = new MobileBarcodeScanningOptions(); opt.DelayBetweenContinuousScans = 3000; //Start scanning scanner.ScanContinuously(opt, true, HandleScanResult); }), new StyledStringElement("Scan with Custom View", async() => { //Create an instance of our custom overlay customOverlay = new CustomOverlayView(); //Wireup the buttons from our custom overlay customOverlay.ButtonTorch.TouchUpInside += delegate { scanner.ToggleTorch(); }; customOverlay.ButtonCancel.TouchUpInside += delegate { scanner.Cancel(); }; //Tell our scanner to use our custom overlay scanner.UseCustomOverlay = true; scanner.CustomOverlay = customOverlay; var result = await scanner.Scan(); HandleScanResult(result); }), new StyledStringElement("Scan with AVCapture Engine", async() => { //Tell our scanner to use the default overlay scanner.UseCustomOverlay = false; //We can customize the top and bottom text of the default overlay scanner.TopText = "Hold camera up to barcode to scan"; scanner.BottomText = "Barcode will automatically scan"; //Start scanning var result = await scanner.Scan(true); HandleScanResult(result); }), new StyledStringElement("Generate Barcode", () => { NavigationController.PushViewController(new ImageViewController(), true); }) } }; }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Initialize the scanner first so we can track the current context MobileBarcodeScanner.Initialize(Application); // Set our view from the "main" layout resource SetContentView(Resource.Layout.AlterarSituacaoQrCode); //Create a new instance of our Scanner scanner = new MobileBarcodeScanner(); buttonScanDefaultView = this.FindViewById <Button>(Resource.Id.buttonScanDefaultView); buttonScanDefaultView.Click += async delegate { //Tell our scanner to use the default overlay scanner.UseCustomOverlay = false; //We can customize the top and bottom text of the default overlay scanner.TopText = "Para evitar erros na leitura.\n Segure o dispositivo a 15 centimetros do código de barras."; scanner.BottomText = "Coloque um código de barras no visor da câmera para digitalizá-lo."; //Start scanning var result = await scanner.Scan(); HandleScanResult(result); }; buttonContinuousScan = FindViewById <Button>(Resource.Id.buttonScanContinuous); buttonContinuousScan.Click += delegate { scanner.UseCustomOverlay = false; //We can customize the top and bottom text of the default overlay scanner.TopText = "Para evitar erros na leitura.\n Segure o dispositivo a 15 centimetros do código de barras."; scanner.BottomText = "Coloque um código de barras no visor da câmera para digitalizá-lo."; var opt = new MobileBarcodeScanningOptions { DelayBetweenContinuousScans = 2000 }; //Start scanning scanner.ScanContinuously(opt, HandleScanResult); }; Button flashButton; View zxingOverlay; buttonScanCustomView = this.FindViewById <Button>(Resource.Id.buttonScanCustomView); buttonScanCustomView.Click += async delegate { //Tell our scanner we want to use a custom overlay instead of the default scanner.UseCustomOverlay = true; //Inflate our custom overlay from a resource layout zxingOverlay = LayoutInflater.FromContext(this).Inflate(Resource.Layout.ZxingOverlay, null); //Find the button from our resource layout and wire up the click event flashButton = zxingOverlay.FindViewById <Button>(Resource.Id.buttonZxingFlash); flashButton.Click += (sender, e) => scanner.ToggleTorch(); //Set our custom overlay scanner.CustomOverlay = zxingOverlay; //Start scanning! var result = await scanner.Scan(); HandleScanResult(result); }; buttonFragmentScanner = FindViewById <Button>(Resource.Id.buttonFragment); buttonFragmentScanner.Click += delegate { StartActivity(typeof(FragmentActivity)); }; buttonGenerate = FindViewById <Button>(Resource.Id.buttonGenerate); buttonGenerate.Click += delegate { StartActivity(typeof(ImageActivity)); }; }
private void SetupButtons() { Button scanButton = FindViewById <Button>(Resource.Id.scanButton); scanButton.Click += async delegate { scanner.UseCustomOverlay = false; //Text as suggested by Zxing scanner.TopText = "Hold the camera up to the barcode\nAbout 6 inches away"; scanner.BottomText = "Wait for the barcode to automatically scan!"; try { //Start scanning var result = await scanner.Scan(); HandleScanResult(result); } catch (Exception e) { this.RunOnUiThread(() => Toast.MakeText(this, "Scan failed: " + e.Message, ToastLength.Short).Show()); } }; //Continous Scan button Button scanPlusButton = FindViewById <Button>(Resource.Id.scanContinuousButton); scanPlusButton.Click += delegate { scanner.UseCustomOverlay = false; scanner.TopText = "Hold the camera up to the barcode\nAbout 6 inches away"; scanner.BottomText = "Wait for the barcode to automatically scan!"; var options = new MobileBarcodeScanningOptions(); options.DelayBetweenContinuousScans = 2000; try { //Start scanning scanner.ScanContinuously(options, HandleScanResult); } catch (Exception e) { this.RunOnUiThread(() => Toast.MakeText(this, "Scan failed: " + e.Message, ToastLength.Short).Show()); } }; Button clearButton = FindViewById <Button>(Resource.Id.clearButton); //Clear displayed barcodes clearButton.Click += delegate { adapter.Clear(); }; Button submitButton = FindViewById <Button>(Resource.Id.submitButton); //Display Concatenated Scanned Results submitButton.Click += delegate { StringBuilder builder = new StringBuilder(); string name = builder.ToString(); for (int i = 0; i < adapter.Count; i++) { builder.Append(adapter.GetItem(i)); } AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.SetTitle("Submitted"); //In case we scan a lot of barcodes make view scrollable TextView msg = new TextView(this); msg.MovementMethod = new ScrollingMovementMethod(); msg.Text = builder.ToString(); alert.SetView(msg); alert.SetPositiveButton("OK", (senderAlert, arg) => {}); alert.Show(); }; }