Example #1
0
        public void UITestBackdoorScan (string param)
        {
            var expectedFormat = ZXing.BarcodeFormat.QR_CODE;
            Enum.TryParse (param, out expectedFormat);
            var opts = new ZXing.Mobile.MobileBarcodeScanningOptions {
                PossibleFormats = new List<ZXing.BarcodeFormat> { expectedFormat }
            };

            System.Diagnostics.Debug.WriteLine ("Scanning " + expectedFormat);

            var scanPage = new ZXingScannerPage (opts);
            scanPage.OnScanResult += (result) => {
                scanPage.IsScanning = false;

                Device.BeginInvokeOnMainThread (() => {
                    var format = result?.BarcodeFormat.ToString () ?? string.Empty;
                    var value = result?.Text ?? string.Empty;

                    MainPage.Navigation.PopAsync ();
                    MainPage.DisplayAlert ("Barcode Result", format + "|" + value, "OK");
                });
            };

            MainPage.Navigation.PushAsync (scanPage);
        }
Example #2
0
        public async Task Navigate()
        {
            ZXing.Mobile.MobileBarcodeScanner option = new ZXing.Mobile.MobileBarcodeScanner();

            var scanner = new ZXing.Mobile.MobileBarcodeScanningOptions()
            {
                TryHarder   = true,
                AutoRotate  = false,
                TryInverted = true,
                DelayBetweenContinuousScans = 2000,
            };

            ZXingScannerPage scanPage = new ZXingScannerPage(scanner);

            await Navigation.PushAsync(scanPage);

            scanPage.OnScanResult += (result) =>
            {
                scanPage.IsScanning = false;
                ZXing.BarcodeFormat barcodeFormat = result.BarcodeFormat;
                string type = barcodeFormat.ToString();
                Device.BeginInvokeOnMainThread(() =>
                {
                    Navigation.PopAsync();
                    DisplayAlert("The Barcode type is : " + type, "The text is : " + result.Text, "OK");
                });
            };
        }
Example #3
0
        private async void ScanQRCode(object obj)
        {
            var options = new ZXing.Mobile.MobileBarcodeScanningOptions
            {
                PossibleFormats = new List <ZXing.BarcodeFormat> {
                    ZXing.BarcodeFormat.QR_CODE
                }
            };

            var scanner = new ZXing.Mobile.MobileBarcodeScanner();
            var result  = await scanner.Scan(options);

            try
            {
                if (result != null)
                {
                    if (result.Text.StartsWith("http://", StringComparison.InvariantCulture) ||
                        result.Text.StartsWith("https://", StringComparison.InvariantCulture))
                    {
                        Device.OpenUri(new Uri(result.Text));
                    }
                }

                Console.WriteLine("Scanned Barcode: " + result.Text);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
        private async void Scanner_Tapped(object sender, EventArgs e)
        {
            try
            {
                var options = new ZXing.Mobile.MobileBarcodeScanningOptions()
                {
                    AutoRotate  = false,
                    TryInverted = true,
                    TryHarder   = true,
                };
                //options.PossibleFormats = new List<ZXing.BarcodeFormat>()
                //{
                //    ZXing.BarcodeFormat.EAN_8, ZXing.BarcodeFormat.EAN_13
                //};
                var scanner = new ZXing.Mobile.MobileBarcodeScanner();
                var result  = await scanner.Scan(options);

                actLoading.IsRunning = true;
                HandleResult(result);
                actLoading.IsRunning = false;
            }
            catch (Exception ex)
            {
            }
        }
Example #5
0
        // Función para abrir la página del scanner
        async void ScanningPage(object sender, EventArgs e)
        {
            try
            {
                // Se configura el lector de códigos de barras
                var options = new ZXing.Mobile.MobileBarcodeScanningOptions
                {
                    PossibleFormats = new List <ZXing.BarcodeFormat>()
                    {
                        ZXing.BarcodeFormat.CODE_128
                    },
                    TryHarder  = true,
                    AssumeGS1  = true,
                    AutoRotate = true
                };
                var scanner = new ZXing.Mobile.MobileBarcodeScanner();
                var result  = await scanner.Scan(options);

                if (result != null)
                {
                    // Capturamos el código de barras
                    string scanResult = result.Text;
                    // Asignamos su valor a la entrada de texto
                    Entry_CodeBars.Text = scanResult;
                    // Verificamos que el código de barras sea válido
                    await VerifyCodeBars();
                }
            }
            catch (Exception ex)
            {
                await DisplayAlert("Error", ex.Message, "OK");

                return;
            }
        }
Example #6
0
        async void ScanClicked(object sender, EventArgs eventArgs)
        {
            //Navigation.PushAsync(new Search.BookSearchPage("4121024109"));
            var scanner = new ZXing.Mobile.MobileBarcodeScanner();

            scanner.CancelButtonText = "キャンセル";
            scanner.FlashButtonText  = "フラッシュ";
            scanner.AutoFocus();
            var options = new ZXing.Mobile.MobileBarcodeScanningOptions();

            var status = await CrossPermissions.Current.CheckPermissionStatusAsync(Plugin.Permissions.Abstractions.Permission.Camera);

            if (status == Plugin.Permissions.Abstractions.PermissionStatus.Granted)
            {
                var result = await scanner.Scan(options);

                if (result != null)
                {
                    await Navigation.PushAsync(new Search.BookSearchPage(result.Text));
                }
            }
            else
            {
                await DisplayAlert("エラー", "カメラを使用できません", "了解");
            }
        }
        public async Task ScanProofRequest()
        {
            var expectedFormat = ZXing.BarcodeFormat.QR_CODE;
            var opts           = new ZXing.Mobile.MobileBarcodeScanningOptions {
                PossibleFormats = new List <ZXing.BarcodeFormat> {
                    expectedFormat
                }
            };

            var scanner = new ZXing.Mobile.MobileBarcodeScanner();

            var result = await scanner.Scan(opts);

            if (result == null)
            {
                return;
            }

            RequestPresentationMessage presentationMessage;

            try
            {
                presentationMessage = await MessageDecoder.ParseMessageAsync(result.Text) as RequestPresentationMessage
                                      ?? throw new Exception("Unknown message type");
            }
            catch (Exception)
            {
                DialogService.Alert("Invalid Proof Request!");
                return;
            }

            if (presentationMessage == null)
            {
                return;
            }

            try
            {
                var request = presentationMessage.Requests?.FirstOrDefault((Attachment x) => x.Id == "libindy-request-presentation-0");
                if (request == null)
                {
                    DialogService.Alert("scanned qr code does not look like a proof request", "Error");
                    return;
                }
                var proofRequest = request.Data.Base64.GetBytesFromBase64().GetUTF8String().ToObject <ProofRequest>();
                if (proofRequest == null)
                {
                    return;
                }

                var proofRequestViewModel = _scope.Resolve <ProofRequestViewModel>(new NamedParameter("proofRequest", proofRequest),
                                                                                   new NamedParameter("requestPresentationMessage", presentationMessage));

                await NavigationService.NavigateToAsync(proofRequestViewModel);
            }
            catch (Exception xx)
            {
                DialogService.Alert(xx.Message);
            }
        }
        async void btnEscanear_Clicked(object sender, EventArgs e)
        {
            var scann = new ZXingBarcodeImageView();
            //setup options
            var options = new ZXing.Mobile.MobileBarcodeScanningOptions
            {
                AutoRotate = false,
                UseFrontCameraIfAvailable = false,
                TryHarder         = true,
                UseNativeScanning = true,
            };



            var pagina = new ZXingScannerPage();

            pagina.AutoFocus();
            pagina.Title = "Escaneando codigo de barra";

            await Navigation.PushAsync(pagina);

            pagina.OnScanResult += (resultado) =>
            {
                pagina.IsScanning = false;

                Device.BeginInvokeOnMainThread(async() =>
                {
                    await Navigation.PopAsync();
                    lblResultado.Text = resultado.Text;
                });
            };
        }
Example #9
0
        public void UITestBackdoorScan(string param)
        {
            var expectedFormat = ZXing.BarcodeFormat.QR_CODE;

            Enum.TryParse(param, out expectedFormat);
            var opts = new ZXing.Mobile.MobileBarcodeScanningOptions {
                PossibleFormats = new List <ZXing.BarcodeFormat> {
                    expectedFormat
                }
            };

            System.Diagnostics.Debug.WriteLine("Scanning " + expectedFormat);

            var scanPage = new ZXingScannerPage(opts);

            scanPage.OnScanResult += (result) => {
                scanPage.IsScanning = false;

                Device.BeginInvokeOnMainThread(() => {
                    var format = result?.BarcodeFormat.ToString() ?? string.Empty;
                    var value  = result?.Text ?? string.Empty;

                    MainPage.Navigation.PopAsync();
                    MainPage.DisplayAlert("Barcode Result", format + "|" + value, "OK");
                });
            };

            MainPage.Navigation.PushAsync(scanPage);
        }
Example #10
0
        private void SetScanOptions()
        {
            var options = new ZXing.Mobile.MobileBarcodeScanningOptions();

            //options.TryHarder = true;
            //options.TryInverted = true;
            //options.AutoRotate = true;
            options.PossibleFormats = new List <ZXing.BarcodeFormat>();
            options.PossibleFormats.Add(ZXing.BarcodeFormat.QR_CODE);
            if (Parameters.Options.AcceptBarcode_Code)
            {
                options.PossibleFormats.Add(ZXing.BarcodeFormat.CODE_39);
                options.PossibleFormats.Add(ZXing.BarcodeFormat.CODE_93);
                options.PossibleFormats.Add(ZXing.BarcodeFormat.CODE_128);
                options.PossibleFormats.Add(ZXing.BarcodeFormat.CODABAR);
            }
            if (Parameters.Options.AcceptBarcode_Ean)
            {
                options.PossibleFormats.Add(ZXing.BarcodeFormat.EAN_8);
                options.PossibleFormats.Add(ZXing.BarcodeFormat.EAN_13);
            }
            if (Parameters.Options.AcceptBarcode_Upc)
            {
                options.PossibleFormats.Add(ZXing.BarcodeFormat.UPC_A);
                options.PossibleFormats.Add(ZXing.BarcodeFormat.UPC_E);
                options.PossibleFormats.Add(ZXing.BarcodeFormat.UPC_EAN_EXTENSION);
            }

            zxing.Options = options;
        }
Example #11
0
        async void ScanAsync(object sender, EventArgs e)
        {
            var options = new ZXing.Mobile.MobileBarcodeScanningOptions();

            options.PossibleFormats = new List <ZXing.BarcodeFormat>()
            {
                ZXing.BarcodeFormat.QR_CODE
            };
            var scanPage = new ZXingScannerPage(options);

            var waitHandle = new EventWaitHandle(false, EventResetMode.AutoReset);

            scanPage.OnScanResult += (result) => {
                // Stop scanning
                scanPage.IsScanning = false;

                viewModel.ScannedId = result.Text;

                waitHandle.Set();

                // Pop the scanner page
                Device.BeginInvokeOnMainThread(() => {
                    Navigation.PopModalAsync();
                });
            };

            // Navigate to our scanner page
            await Navigation.PushModalAsync(scanPage);
        }
        public async Task ScanInvite()
        {
            ConnectionInvitationMessage invitation = null;
            bool isEmulated = false;  //ONLY FOR TESTING

            if (!isEmulated)
            {
                var expectedFormat = ZXing.BarcodeFormat.QR_CODE;
                var opts           = new ZXing.Mobile.MobileBarcodeScanningOptions
                {
                    PossibleFormats = new List <ZXing.BarcodeFormat> {
                        expectedFormat
                    }
                };

                var scanner = new ZXing.Mobile.MobileBarcodeScanner();

                var result = await scanner.Scan(opts);

                if (result == null)
                {
                    return;
                }

                try
                {
                    invitation = await MessageDecoder.ParseMessageAsync(result.Text) as ConnectionInvitationMessage
                                 ?? throw new Exception("Unknown message type");
                }
                catch (Exception)
                {
                    DialogService.Alert("Invalid invitation!");
                    return;
                }
            }
            else
            {
                invitation = new ConnectionInvitationMessage()
                {
                    Id            = "453b0d8e-50d0-4a18-bf44-7d7369a0c31f",
                    Label         = "Verifier",
                    Type          = "did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/connections/1.0/invitation",
                    ImageUrl      = "",
                    RecipientKeys = new List <string>()
                    {
                        "DPqj1fdVajDYdVgeT36NUSoVghjkapaHpVUdwbL1z6ye"
                    },
                    RoutingKeys = new List <string>()
                    {
                        "9RUPb4jPtR2S1P9yVy85ugwiywqqzDfxRrDZnKCTQCtH"
                    },
                    ServiceEndpoint = "http://mylocalhost:5002"
                };
            }
            Device.BeginInvokeOnMainThread(async() =>
            {
                await NavigationService.NavigateToAsync <AcceptInviteViewModel>(invitation, NavigationType.Modal);
            });
        }
Example #13
0
        public async Task <string> ScanAsync()
        {
            #region 使用 ZXing.Mobile 的 MobileBarcodeScanner
            // http://stackoverflow.com/questions/34582728/how-to-find-current-uiviewcontroller-in-xamarin

            #region 取得最上層的 UIViewController
            var window = UIApplication.SharedApplication.KeyWindow;
            var vc     = window.RootViewController;
            while (vc.PresentedViewController != null)
            {
                vc = vc.PresentedViewController;
            }

            UIViewController appController = null;
            foreach (var foowindow in UIApplication.SharedApplication.Windows)
            {
                if (foowindow.RootViewController != null)
                {
                    appController = foowindow.RootViewController;
                    break;
                }
            }
            #endregion

            #region QRCode 掃描設定
            var options = new ZXing.Mobile.MobileBarcodeScanningOptions();
            options.PossibleFormats = new List <ZXing.BarcodeFormat>()
            {
                ZXing.BarcodeFormat.QR_CODE,
            };
            #endregion

            #region 進行 QRCode 掃描
            var scanner = new ZXing.Mobile.MobileBarcodeScanner(vc)
            {
                TopText = "QRCode",
            };
            try
            {
                var scanResults = await scanner.Scan(options, true);

                if (scanner != null)
                {
                    return(scanResults.Text);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(null);
            }
            #endregion

            #endregion
        }
		//
		// This method is invoked when the application has loaded and is ready to run. In this 
		// method you should instantiate the window, load the UI into it and then make the window
		// visible.
		//
		// You have 17 seconds to return from this method, or iOS will terminate your application.
		//
		public override bool FinishedLaunching (UIApplication app, NSDictionary options)
		{
			JsBridge.EnableJsBridge();

			window = new UIWindow (UIScreen.MainScreen.Bounds);

			// get useragent
			UIWebView agentWebView = new UIWebView ();
			var userAgent = agentWebView.EvaluateJavascript ("navigator.userAgent");
			agentWebView = null;
			userAgent += " XamarinBarcodeSampleApp";

			// set default useragent
			NSDictionary dictionary = NSDictionary.FromObjectAndKey(NSObject.FromObject(userAgent), NSObject.FromObject("UserAgent"));
			NSUserDefaults.StandardUserDefaults.RegisterDefaults(dictionary);

			viewController = new Xamarin_iOS_BarcodeSampleViewController ();
			window.RootViewController = viewController;
			window.MakeKeyAndVisible ();

			viewController.MainWebView.LoadRequest(new NSUrlRequest(new NSUrl("http://xamarinbarcodesample.apphb.com/")));

			// listen for the event triggered by the browser.
			viewController.MainWebView.AddEventListener( "scanBarcode", delegate(FireEventData arg) {

				// show a native action sheet
				BeginInvokeOnMainThread (delegate { 
					//NOTE: On Android you MUST pass a Context into the Constructor!
					var scanningOptions = new ZXing.Mobile.MobileBarcodeScanningOptions();
					scanningOptions.PossibleFormats = new List<ZXing.BarcodeFormat>() { 
						ZXing.BarcodeFormat.All_1D
					};
					scanningOptions.TryInverted = true;
					scanningOptions.TryHarder = true;
					scanningOptions.AutoRotate = false;
					var scanner = new ZXing.Mobile.MobileBarcodeScanner();
					scanner.TopText = "Hold camera up to barcode to scan";
					scanner.BottomText = "Barcode will automatically scan";
					scanner.Scan(scanningOptions).ContinueWith(t => {   
						if (t.Result != null) {
							//Console.WriteLine("Scanned Barcode: " + t.Result.Text);

							// pass barcode back to browser.
							viewController.MainWebView.FireEvent( "scanComplete", new {
								code = t.Result.Text
							});
						}
					});
				});

			});
			
			return true;
		}
        /// <summary>
        /// Scan QR Code
        /// </summary>
        private async void tiQRCode_Activated(object sender, EventArgs e)
        {
            if (!App.AppSettings.QRCodeEnabled)
            {
                return;
            }

            var expectedFormat = ZXing.BarcodeFormat.QR_CODE;
            var opts           = new ZXing.Mobile.MobileBarcodeScanningOptions
            {
                PossibleFormats = new List <ZXing.BarcodeFormat> {
                    expectedFormat
                }
            };

            System.Diagnostics.Debug.WriteLine("Scanning " + expectedFormat);

            var scanPage = new ZXingScannerPage(opts);

            scanPage.OnScanResult += (result) =>
            {
                scanPage.IsScanning = false;

                Device.BeginInvokeOnMainThread(async() =>
                {
                    await Navigation.PopAsync();
                    try
                    {
                        var qrCodeId = result.Text.GetHashCode() + "";
                        var qrCode   = App.AppSettings.QRCodes.FirstOrDefault(o => o.Id == qrCodeId);
                        if (qrCode != null && qrCode.Enabled)
                        {
                            App.AddLog("QR Code ID Found: " + qrCodeId);
                            App.ShowToast(AppResources.qrcode + " " + qrCode.Name);
                            await App.ApiService.HandleSwitch(qrCode.SwitchIDX, qrCode.SwitchPassword, -1, qrCode.Value,
                                                              qrCode.IsScene);
                            App.SetMainPage();
                        }
                        else
                        {
                            App.AddLog("QR Code ID not registered: " + qrCodeId);
                            App.ShowToast(
                                qrCode == null ? AppResources.qrcode_new_found : AppResources.qr_code_disabled);
                        }
                    }
                    catch (Exception ex)
                    {
                        App.AddLog(ex.Message);
                    }
                });
            };

            await Navigation.PushAsync(scanPage);
        }
Example #16
0
        private async void Button_Clicked(object sender, EventArgs e)
        {
            var option = new ZXing.Mobile.MobileBarcodeScanningOptions();

            option.AutoRotate      = true;
            option.PossibleFormats = new List <ZXing.BarcodeFormat>()
            {
                ZXing.BarcodeFormat.EAN_8, ZXing.BarcodeFormat.EAN_13, ZXing.BarcodeFormat.CODE_128
            };
            var scanPage = new ZXingScannerPage(option);

            scanPage.HeightRequest = 300;
            scanPage.WidthRequest  = 200;

            scanPage.OnScanResult += (result) =>
            {
                // Stop scanning
                scanPage.IsScanning = false;
                if (scanPage.IsScanning)
                {
                    scanPage.AutoFocus();
                }

                // Pop the page and show the result
                Device.BeginInvokeOnMainThread(async() =>
                {
                    await Navigation.PopAsync();
                    // await DisplayAlert("Scanned Barcode", result.Text, "OK");
                    try
                    {
                        var data = result.Text.Split(';');
                        if (data.Length > 0)
                        {
                            var context    = BindingContext as TracingViewModel;
                            var resultData = await context.Find(data[0], data[1]);
                            if (result != null)
                            {
                                await Navigation.PushAsync(new TrackingDetail(resultData));
                            }
                        }
                        else
                        {
                            throw new SystemException("Ulangi Scan QR Code");
                        }
                    }
                    catch (Exception ex)
                    {
                        await DisplayAlert("Error", ex.Message, "OK");
                    }
                });
            };
            // Navigate to our scanner page
            await Navigation.PushAsync(scanPage);
        }
Example #17
0
        public async Task SetOptionsBarcode()
        {
            var options = new ZXing.Mobile.MobileBarcodeScanningOptions();

            options.PossibleFormats = new List <ZXing.BarcodeFormat>()
            {
                ZXing.BarcodeFormat.EAN_8, ZXing.BarcodeFormat.EAN_13
            };

            var scanner = new ZXing.Mobile.MobileBarcodeScanner();
            var result  = await scanner.Scan(options);
        }
Example #18
0
        async void ScanAsync(object sender, EventArgs e)
        {
            var options = new ZXing.Mobile.MobileBarcodeScanningOptions();

            options.PossibleFormats = new List <ZXing.BarcodeFormat>()
            {
                ZXing.BarcodeFormat.QR_CODE
            };
            var scanPage = new ZXingScannerPage(options);

            var waitHandle = new EventWaitHandle(false, EventResetMode.AutoReset);

            string scannedId = null;

            scanPage.OnScanResult += (result) => {
                // Stop scanning
                scanPage.IsScanning = false;

                scannedId = result.Text;
                waitHandle.Set();

                // Pop the page and show the result
                Device.BeginInvokeOnMainThread(() => {
                    Navigation.PopModalAsync();
                });
            };

            // Navigate to our scanner page
            await Navigation.PushModalAsync(scanPage);

            await Task.Run(() => waitHandle.WaitOne());

            if (scannedId == null)
            {
                return;
            }

            if (!uuidValidator.IsMatch(scannedId))
            {
                DependencyService.Get <IToastMessage>().ShortAlert("Ungültiger Code!");
            }

            if (scannedId != authController.AuthToken.UserId)
            {
                await historyController.SetScannedNow(scannedId);
            }

            await ShowProfile(scannedId);
        }
Example #19
0
        public async Task <string> ScanAsync()
        {
            var scanner = new ZXing.Mobile.MobileBarcodeScanner()
            {
                UseCustomOverlay = true
            };

            var options = new ZXing.Mobile.MobileBarcodeScanningOptions()
            {
                TryHarder  = true,
                AutoRotate = false,
                UseFrontCameraIfAvailable = false,
                PossibleFormats           = new List <ZXing.BarcodeFormat>()
                {
                    ZXing.BarcodeFormat.QR_CODE
                }
            };

            ScannerOverlayView customOverlay = new ScannerOverlayView();

            customOverlay.OnCancel += () =>
            {
                scanner?.Cancel();
            };
            customOverlay.OnResume += () =>
            {
                scanner?.ResumeAnalysis();
            };
            customOverlay.OnPause += () =>
            {
                scanner?.PauseAnalysis();
            };
            scanner.CustomOverlay = customOverlay;


            ZXing.Result scanResults = null;
            scanResults = await scanner.Scan(options);

            //customOverlay.Dispose();
            if (scanResults != null)
            {
                return(scanResults.Text);
            }
            return(string.Empty);
        }
Example #20
0
		//Implementamos el metodo Scan definido en la interfaz IScan
		public async System.Threading.Tasks.Task<String> Scan(){

			var ctx = Forms.Context;

			var options = new ZXing.Mobile.MobileBarcodeScanningOptions();
			options.PossibleFormats = new System.Collections.Generic.List<ZXing.BarcodeFormat>()
			{
				ZXing.BarcodeFormat.QR_CODE,
			};

			var scanner = new ZXing.Mobile.MobileBarcodeScanner(ctx);
			var result = await scanner.Scan(options);

			if(result != null)
				return result.ToString ();

			return string.Empty;
		} 
Example #21
0
        public async void quickScan()
        {
            var options = new ZXing.Mobile.MobileBarcodeScanningOptions();

            // Restrict to QR codes only
            options.PossibleFormats = new List <ZXing.BarcodeFormat>()
            {
                ZXing.BarcodeFormat.QR_CODE
            };

            var ScannerPage = new ZXingScannerPage(options);


            ScannerPage.OnScanResult += (result) => {
                ScannerPage.IsScanning  = false;
                ScannerPage.IsAnalyzing = false;
                Device.BeginInvokeOnMainThread(() => {
                    Navigation.PopAsync(Config.defaultXamarinAnimations);

                    if (result.Text.Contains(":ixi"))
                    {
                        string[] split = result.Text.Split(new string[] { ":ixi" }, StringSplitOptions.None);
                        if (split.Count() < 1)
                        {
                            return;
                        }
                        string wal = split[0];
                        webView.Eval(string.Format("setAddress(\"{0}\")", wal));
                    }
                    else
                    {
                        string wal = result.Text;
                        // TODO: enter exact Ixian address length
                        if (wal.Length > 20 && wal.Length < 128)
                        {
                            webView.Eval(string.Format("setAddress(\"{0}\")", wal));
                        }
                    }
                });
            };


            await Navigation.PushAsync(ScannerPage, Config.defaultXamarinAnimations);
        }
Example #22
0
        public async Task ScanAsync()
        {
            _stopped = false;

            // Initialize the scanner first so it can track the current context
            ZXing.Mobile.MobileBarcodeScanner.Initialize(_androidApplication);


            var scanner = new ZXing.Mobile.MobileBarcodeScanner();

            var opt = new ZXing.Mobile.MobileBarcodeScanningOptions()
            {
                // DelayBetweenContinuousScans = 1000,
                UseNativeScanning = true,
            };

            scanner.ScanContinuously(opt, f);
            // return null;
        }
Example #23
0
        public async void quickScan()
        {
            var options = new ZXing.Mobile.MobileBarcodeScanningOptions();

            // Restrict to QR codes only
            options.PossibleFormats = new List <ZXing.BarcodeFormat>()
            {
                ZXing.BarcodeFormat.QR_CODE
            };

            var ScannerPage = new ZXingScannerPage(options);


            ScannerPage.OnScanResult += (result) => {
                ScannerPage.IsScanning = false;

                Device.BeginInvokeOnMainThread(() => {
                    Navigation.PopAsync(Config.defaultXamarinAnimations);

                    // Check for add contact
                    string[] split = result.Text.Split(new string[] { ":ixi" }, StringSplitOptions.None);
                    if (split.Count() > 1)
                    {
                        string id_to_add = split[0];
                        Navigation.PushAsync(new ContactNewPage(id_to_add), Config.defaultXamarinAnimations);
                        return;
                    }

                    // Check for transaction request
                    split = result.Text.Split(new string[] { ":send:" }, StringSplitOptions.None);
                    if (split.Count() > 1)
                    {
                        byte[] wallet_to_send = Base58Check.Base58CheckEncoding.DecodePlain(split[0]);
                        Navigation.PushAsync(new WalletSendPage(wallet_to_send), Config.defaultXamarinAnimations);
                        return;
                    }
                });
            };


            await Navigation.PushAsync(ScannerPage, Config.defaultXamarinAnimations);
        }
Example #24
0
        public async static Task <ZXingScannerPage> CaptureQRCodeAsync(ZXingScannerPage scanPage, string title, ZXing.BarcodeFormat format)
        {
            //Create page do QRCode
            if (scanPage == null)
            {
                var options = new ZXing.Mobile.MobileBarcodeScanningOptions();
                options.PossibleFormats = new List <ZXing.BarcodeFormat>
                {
                    format
                };
//Start correctly the plugins of Scanner
#if __ANDROID__
                MobileBarcodeScanner.Initialize(Application);
#endif

                scanPage            = new ZXingScannerPage(options); //Creata a new instance
                scanPage.IsScanning = true;                          //Start camera and qrCode
            }
            scanPage.Title = title;                                  //Title
            return(scanPage);                                        //return page
        }
Example #25
0
        //Implementamos el metodo Scan definido en la interfaz IScan
        public async System.Threading.Tasks.Task <String> Scan()
        {
            var ctx = Forms.Context;

            var options = new ZXing.Mobile.MobileBarcodeScanningOptions();

            options.PossibleFormats = new System.Collections.Generic.List <ZXing.BarcodeFormat>()
            {
                ZXing.BarcodeFormat.QR_CODE,
            };

            var scanner = new ZXing.Mobile.MobileBarcodeScanner(ctx);
            var result  = await scanner.Scan(options);

            if (result != null)
            {
                return(result.ToString());
            }

            return(string.Empty);
        }
        /// <summary>
        /// Create connection by presenting in-app QR code scanner.
        /// </summary>
        /// <param name="ctx"></param>
        /// <returns></returns>
        public static async Task<bool> EstablishSenderConnection(Activity ctx)
        {
            var overlay = ctx.LayoutInflater.Inflate(Resource.Layout.ScannerOverlay, null);

            var options = new ZXing.Mobile.MobileBarcodeScanningOptions()
            {
                PossibleFormats = new System.Collections.Generic.List<ZXing.BarcodeFormat>() { ZXing.BarcodeFormat.QR_CODE }
            };
            var scanner = new ZXing.Mobile.MobileBarcodeScanner(ctx)
            {
                UseCustomOverlay = true,
                CustomOverlay = overlay
            };
            var result = await scanner.Scan(options);

            if (result == null)
                return false;

            string resString = result.Text;

            if (resString == QR.DataSchemeWithSuffix + "sound")
            {
                // the secret special mode. makes it possible to test features without another device.
                // scan this: http://chart.apis.google.com/chart?chs=500x500&cht=qr&chl=dltsec://sound
                Network.SenderConnection.CreateWithoutEndpoint();
                Network.SenderConnection.CurrentConnection.RemoteName = "nobody";
                return true;
            }

            if (!Features.QR.IsValid(resString))
                throw new InvalidQRCodeException();

            string host, password;
            int port;
            Features.QR.GetComponents(resString, out host, out port, out password);

            return await EstablishSenderConnection(ctx, host, port, password);
        }