public void OnServiceConnected(ComponentName name, IBinder service) { // Logger.Debug( $"TachoHelper: OnServiceConnected {name.ClassName}"); Messenger = new Messenger(service); IsConnected = this.Messenger != null; if (IsConnected) { P8Event?.Invoke(this, new P8EventData("tachocontroller", "info", "tachoinfo", "Tacho Service connected", "connected")); // Toast.MakeText(Android.App.Application.Context, Resource.String.service_started, ToastLength.Short).Show(); } else { P8Event?.Invoke(this, new P8EventData("tachocontroller", "info", "tachoerror", "Tacho Service cann't connected", "connected false")); Toast.MakeText(Android.App.Application.Context, "Service cann't connected...", ToastLength.Short).Show(); } }
public virtual void StopTachoProcess() { try { if (serviceConnection?.Messenger != null) { Message msg = Message.Obtain(null, Constants.TachoConrollerOperation); try { Bundle dataToSend = new Bundle(); dataToSend.PutString("cmd", "stop"); msg.Data = dataToSend; msg.ReplyTo = activityMessenger; serviceConnection.Messenger.Send(msg); //serviceConnection.Messenger.Dispose(); } catch (RemoteException ex) { P8Event?.Invoke(this, new P8EventData("tachocontroller", "error", "tachoerror", "There was a error trying to send the message", "")); Log.Error(TAG, ex, "TachoHelper: There was a error trying to send the message"); } } else { P8Event?.Invoke(this, new P8EventData("tachocontroller", "error", "tachoerror", "There was a error trying to send the message", "")); Toast.MakeText(Android.App.Application.Context, "TachoService cann't connected", ToastLength.Short).Show(); } /* if (serviceConnection != null) * { * Android.App.Application.Context.UnbindService(serviceConnection); * }*/ } catch (Exception ex) { Log.Warn("tachotag", "TachoHelper: Exception Stop TachoIntentService for gettahodata Message:" + ex.Message); } }
public void OnServiceDisconnected(ComponentName name) { P8Event?.Invoke(this, new P8EventData("tachocontroller", "info", "tachoinfo", "Tacho Service disconnected", "")); Log.Debug("tachotag", $"TachoService disconnected {name.ClassName}"); }
public virtual void StartService() { Logger.Debug("TachoHelper: Sending StartService cmd"); isStarting = false; if (!IsTachoServicePackageInstalled()) { Log.Error(TAG, "TachoHelper: TachoService is not installed"); P8Event?.Invoke(this, new P8EventData("tachocontroller", "error", "tachoerror", "TachoService is not installed", "connected false")); Toast.MakeText(Android.App.Application.Context.ApplicationContext, "TachoService is not installed on Device", ToastLength.Long).Show(); return; } if (HasPermissionToRunTachoService()) { Logger.Debug("TachoHelper: TachoService is calling..."); if (activityMessenger == null) { var mesr = new TachoServiceHandler(); activityMessenger = new Messenger(mesr); mesr.P8Event += (s, e) => { string mes = $"TachoHelper: mesr.P8Event += EventName: {e.EventName} Description: {e.Description} "; if (e.EventName == "tachopid" && TachoservicePid == 0) { TachoservicePid = Convert.ToInt32(e.Parametr); // Android.OS.Process.KillProcess(TachoservicePid); } Log.Debug("tachotag", mes); P8Event?.Invoke(this, e); }; } if (serviceConnection == null) { serviceConnection = new TachoServiceConnection(); serviceConnection.P8Event += (s, e) => { if (e.EventName == "tachoinfo" && (string)e.Parametr == "connected") { GetPid(); } P8Event?.Invoke(this, e); }; } if (intentToBindService == null) { intentToBindService = CreateIntentToBindService(Android.App.Application.Context); } Android.App.Application.Context.BindService(intentToBindService, serviceConnection, Bind.AutoCreate); isStarting = true; Logger.Debug("TachoHelper: TachoService has been called."); } else { Log.Error(TAG, $"TachoHelper: No permissions to use the service {Constants.REMOTE_SERVICE_PACKAGE_NAME}."); serviceConnection = null; activityMessenger = null; Toast.MakeText(Android.App.Application.Context.ApplicationContext, "You must grant permission before this app can use the TachoService", ToastLength.Long).Show(); P8Event?.Invoke(this, new P8EventData("tachocontroller", "error", "tachoerror", "You must grant permission before this app can use the TachoService.", "connected false")); return; } }