/// <summary> /// Scans the barcode. /// </summary> /// <param name="options">Parameter is ignored.</param> public void scan(string options) { var task = new BarcodeScannerTask(); task.Completed += this.TaskCompleted; task.Show(); }
/// <summary> /// Handler for barcode scanner task. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The scan result.</param> private void TaskCompleted(object sender, BarcodeScannerTask.ScanResult e) { PluginResult result; switch (e.TaskResult) { case TaskResult.OK: result = new PluginResult(PluginResult.Status.OK); result.Message = JsonHelper.Serialize(new BarcodeResult(e.Barcode)); break; case TaskResult.Cancel: // If scan is cancelled we return PluginResult.Status.OK with Message contains cancelled: true // See plugin docs https://github.com/MSOpenTech/BarcodeScanner#using-the-plugin result = new PluginResult(PluginResult.Status.OK); result.Message = JsonHelper.Serialize(new BarcodeResult()); break; default: result = new PluginResult(PluginResult.Status.ERROR); break; } this.DispatchCommandResult(result); }