private void InitDriver() { try { if (_driverManager.Started) { return; } _loggingService.Info("Initializing device"); var req = new Intent(Intent.ActionView); req.SetData(new Android.Net.Uri.Builder().Scheme("dtvdriver").Build()); req.PutExtra(Intent.ExtraReturnResult, true); _waitingForInit = true; Task.Run(async() => { await Task.Delay(5000); // wait 5 secs; if (_waitingForInit) { _waitingForInit = false; _loggingService.Error("Device response timeout"); MessagingCenter.Send("response timeout", BaseViewModel.MSG_DVBTDriverConfigurationFailed); } }); StartActivityForResult(req, StartRequestCode); #if TestingDVBTDriverManager _waitingForInit = false; var cfg = new DVBTDriverConfiguration() { DeviceName = "Testing device" }; MessagingCenter.Send(cfg.ToString(), BaseViewModel.MSG_DVBTDriverConfiguration); #endif } catch (ActivityNotFoundException ex) { _waitingForInit = false; _loggingService.Error(ex, "Device initializing failed"); MessagingCenter.Send("DVBT driver not installed", BaseViewModel.MSG_DVBTDriverConfigurationFailed); } catch (Exception ex) { _waitingForInit = false; _loggingService.Error(ex, "Driver initializing failed"); MessagingCenter.Send("connection failed", BaseViewModel.MSG_DVBTDriverConfigurationFailed); } }
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) { InAppBillingImplementation.HandleActivityResult(requestCode, resultCode, data); if (requestCode == StartRequestCode && resultCode == Result.Ok) { _waitingForInit = false; if (data != null) { var cfg = new DVBTDriverConfiguration(); if (data.HasExtra("ControlPort")) { cfg.ControlPort = data.GetIntExtra("ControlPort", 0); } if (data.HasExtra("TransferPort")) { cfg.TransferPort = data.GetIntExtra("TransferPort", 0); } if (data.HasExtra("DeviceName")) { cfg.DeviceName = data.GetStringExtra("DeviceName"); } if (data.HasExtra("ProductIds")) { cfg.ProductIds = data.GetIntArrayExtra("ProductIds"); } if (data.HasExtra("VendorIds")) { cfg.VendorIds = data.GetIntArrayExtra("VendorIds"); } _loggingService.Info($"Received device configuration: {cfg}"); MessagingCenter.Send(cfg.ToString(), BaseViewModel.MSG_DVBTDriverConfiguration); } else { MessagingCenter.Send("no response", BaseViewModel.MSG_DVBTDriverConfigurationFailed); } } }