public void DidScan(IScanSession session) { if (session.NewlyRecognizedCodes.Count > 0) { if (!ContinuousAfterScan) { // Call GC.Collect() before stopping the scanner as the garbage collector for some reason does not // collect objects without references asap but waits for a long time until finally collecting them. GC.Collect(); // Stop the scanner directly on the session. session.PauseScanning(); } // If you want to edit something in the view hierarchy make sure to run it on the UI thread. using (var h = new Android.OS.Handler(Android.OS.Looper.MainLooper)) { h.Post(() => { var symbologies = ""; var data = ""; foreach (var code in session.NewlyRecognizedCodes) { var separator = symbologies.Length == 0 ? "" : ", "; symbologies += separator + code.SymbologyName; data += separator + code.Data; } PickerView.DidScan(symbologies, data); }); } } }
public override void DidScan(BarcodePicker picker, IScanSession session) { if (session.NewlyRecognizedCodes.Count > 0) { if (!ContinuousAfterScan) { // Stop the scanner directly on the session. session.PauseScanning(); } // If you want to edit something in the view hierarchy make sure to run it on the UI thread. UIApplication.SharedApplication.InvokeOnMainThread(() => { var symbologies = ""; var data = ""; foreach (var code in session.NewlyRecognizedCodes) { var separator = symbologies.Length == 0 ? "" : ", "; symbologies += separator + code.SymbologyString; data += separator + code.Data; } PickerView.DidScan(symbologies, data); }); } }
public void DidScan(IScanSession session) { if (session.NewlyRecognizedCodes.Count > 0) { Barcode code = session.NewlyRecognizedCodes[0]; Console.WriteLine("barcode scanned: {0}, '{1}'", code.SymbologyName, code.Data); // Call GC.Collect() before stopping the scanner as the garbage collector for some reason does not // collect objects without references asap but waits for a long time until finally collecting them. GC.Collect(); // Stop the scanner directly on the session. session.PauseScanning(); // If you want to edit something in the view hierarchy make sure to run it on the UI thread. RunOnUiThread(() => { AlertDialog alert = new AlertDialog.Builder(this) .SetTitle(code.SymbologyName + " Barcode Detected") .SetMessage(code.Data) .SetPositiveButton("OK", delegate { scanButton.Visibility = ViewStates.Visible; }) .SetOnCancelListener(this) .Create(); alert.Show(); }); } }
public override void DidScan(BarcodePicker picker, IScanSession session) { if (session.NewlyRecognizedCodes.Count > 0) { Barcode code = session.NewlyRecognizedCodes.GetItem <Barcode>(0); Console.WriteLine("barcode scanned: {0}, '{1}'", code.SymbologyString, code.Data); // Pause the scanner directly on the session. session.PauseScanning(); // If you want to edit something in the view hierarchy make sure to run it on the UI thread. UIApplication.SharedApplication.InvokeOnMainThread(() => { UIAlertView alert = new UIAlertView() { Title = code.SymbologyString + " Barcode Detected", Message = "" + code.Data }; alert.AddButton("OK"); alert.Show(); }); } }