public override void ViewDidLoad() { base.ViewDidLoad(); // Perform any additional setup after loading the view, typically from a nib. status.Text = device.State.ToString(); deviceName.Text = device.Name; deviceId.Text = device.Id.ToString(); var picker = new UIDocumentPickerViewController(allowedUTIs, UIDocumentPickerMode.Open); picker.WasCancelled += Picker_WasCancelled; uploadFile.TouchUpInside += delegate { picker.DidPickDocumentAtUrls += (object s, UIDocumentPickedAtUrlsEventArgs e) => { Console.WriteLine("url = {0}", e.Urls[0].AbsoluteString); //bool success = await MoveFileToApp(didPickDocArgs.Url); var success = true; string filename = e.Urls[0].LastPathComponent; string extension = Path.GetExtension(filename);; string msg = success ? string.Format("Successfully imported file '{0}'", filename) : string.Format("Failed to import file '{0}'", filename); // Some invaild file url returns null NSData data = NSData.FromUrl(e.Urls[0]); if (data != null) { byte[] dataBytes = new byte[data.Length]; System.Runtime.InteropServices.Marshal.Copy(data.Bytes, dataBytes, 0, Convert.ToInt32(data.Length)); for (int i = 0; i < dataBytes.Length; i++) { Console.WriteLine(dataBytes[i]); } } Console.WriteLine(data + "Completed"); var alertController = UIAlertController.Create("import", msg, UIAlertControllerStyle.Alert); var okButton = UIAlertAction.Create("OK", UIAlertActionStyle.Default, (obj) => { alertController.DismissViewController(true, null); }); alertController.AddAction(okButton); PresentViewController(alertController, true, null); }; PresentViewController(picker, true, null); }; updateFirmware.TouchUpInside += delegate { FirmwareUpdaterDelegate firmwareUpdater = new FirmwareUpdater(device.NativeDevice as CBPeripheral); firmwareUpdater.Start(); }; }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.firmware_update); _abortButton = FindViewById <Button>(Resource.Id.fwUpdateAbort); _pauseButton = FindViewById <Button>(Resource.Id.fwUpdatePause); _continueButton = FindViewById <Button>(Resource.Id.fwUpdateContinue); _statusTextView = FindViewById <TextView>(Resource.Id.fwStatusText); _errorTextView = FindViewById <TextView>(Resource.Id.fwErrorText); _successTextView = FindViewById <TextView>(Resource.Id.fwSuccessText); var fwTitleText = FindViewById <TextView>(Resource.Id.fwTitleText); _fwProgressBar = FindViewById <ProgressBar>(Resource.Id.fwProgressBar); _fwProgressSpinner = FindViewById <ProgressBar>(Resource.Id.fwSpinner); fwTitleText.Text = $"Updating device {CurrentParameters.CurrentDevice.Name} with firmware {CurrentParameters.CurrentFirmwareUri.LastPathSegment}:"; _progressListener = new DfuProgressListener(); _updater = new FirmwareUpdater(CurrentParameters.CurrentDevice.Address, CurrentParameters.CurrentFirmwareUri, _progressListener); _updater.Start(); }