private void ConnectWithDevice(int i) { var device = deviceHelper.liDevices[i]; if (DeviceService.isServiceRunning && DeviceService._dsp?.device?.Identifier == device.scanDevice.Identifier) { return; } int delay = 0; if (DeviceService.isServiceRunning) { DeviceService.StopService(true); delay = 400; } nvDrawer.PostDelayed(delegate { try { var dsp = new DeviceServiceParameter(); dsp.device = device.scanDevice; dsp.conFlag = device.conFlag; dsp.id = device.id; StartDeviceService(dsp); } catch (Exception e) { Console.WriteLine(e); Toast.MakeText(this, $"Internal connection error {e.Message}", ToastLength.Long).Show(); } }, delay); }
public void StartDeviceService(DeviceServiceParameter dsp) { if (DeviceService.isServiceRunning) { throw new Exception("Service läuft bereits"); } Intent si = new Intent(Application.Context, typeof(DeviceService)); si.PutExtra(IntentHelper.INTENT_DSP_VAL, dsp.ToString()); StartService(si); }
public override void OnReceive(Context context, Intent intent) { try { NetworkInfo info = (NetworkInfo)intent.GetParcelableExtra(WifiManager.ExtraNetworkInfo); if (info?.IsConnected == true) { //Toast.MakeText(context,"WIFI CONNECTED",ToastLength.Short).Show(); if (!DeviceService.isServiceRunning) { DeviceHelper dh = DeviceHelper.Instance(); foreach (var device in dh.liDevices) { if (device.conFlag == 2) { var dsp = new DeviceServiceParameter { device = device.scanDevice, conFlag = device.conFlag, id = device.id }; Task.Run((() => { System.Threading.Thread.Sleep(2500); StartDeviceService(dsp, context); })); return; } } } } else { if (DeviceService.isServiceRunning) { DeviceService.StopService(true); } } } catch (Exception e) { Console.WriteLine(e); //Toast.MakeText(context,"ERROR: "+e.Message,ToastLength.Short).Show(); } }
public void StartDeviceService(DeviceServiceParameter dsp) { if (DeviceService.isServiceRunning) { if (DeviceService.isServiceConnecting) { throw new Exception("Connecting..."); } if (DeviceService.isServiceConnected) { throw new Exception("Connected"); } throw new Exception("Not connected"); } Intent si = new Intent(Application.Context, typeof(DeviceService)); si.PutExtra(IntentHelper.INTENT_DSP_VAL, dsp.ToString()); Activity.StartService(si); }
public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId) { isServiceRunning = true; OnServiceStatusChangedEvent += OnServiceStatusChanged; _dsp = IntentHelper.GetDeviceServiceParameter(intent); serviceDisconnectReason = null; //Toast.MakeText(Application.Context, "START", ToastLength.Short).Show(); if (_dsp == null) { serviceDisconnectReason = ServiceDisconnectReason.DISC_INTERNAL_ERR; StopService(false); } else { netArt = new CmdHelper.NetArt(); netArt.OnArtStatusChanged = OnArtStatusChanged; BrinNotfiListener.OnReceived = OnReceived; OpenConnection(); } return(StartCommandResult.RedeliverIntent); }