示例#1
0
        public override void OnReceive(Context context, Intent intent)
        {
            if (Info.IntentActionAlarm == intent.Action)
            {
                try
                {
                    if (!HearServices.IsServiceRunning(typeof(NotifyService), context))
                    {
                        Intent serviceIntent;

                        serviceIntent = new Intent(context, typeof(NotifyService));
                        serviceIntent.SetAction(Info.IntentActionStartService);

                        if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.O)
                        {
                            context.StartForegroundService(serviceIntent);
                        }
                        else
                        {
                            context.StartService(serviceIntent);
                        }
                    }
                }
                catch (Exception ex)
                {
                    #region Logging
                    LogRuntimeAttribute.InLogFiles(typeof(AlarmReceiver), ex);
                    #endregion
                }
                finally  { }
            }
        }
示例#2
0
        private void ButtonDefaultSettings_Click(object sender, EventArgs e)
        {
            if (HearServices.IsServiceRunning(typeof(NotifyService), context))
            {
                var remoteViews = new RemoteViews(context.PackageName, Resource.Layout.layout_toast);

                var layoutInflater = LayoutInflater.FromContext(context);
                var view           = layoutInflater.Inflate(remoteViews.LayoutId, null);

                var textView = view.FindViewById <TextView>(Resource.Id.text);

                textView.Text = DefaultSettingsRun;

                Toast toast = new Toast(context);

                toast.SetGravity(GravityFlags.CenterVertical, 0, 0);
                toast.View = view;
                toast.Show();
            }
            else
            {
                Settings settingsDefault = crudSettings.ReadDefault();
                crudSettings.Write(settingsDefault);

                Settings.SetInstance = null;
                settings             = Settings.Instance;

                updatePendingIntent.Send();

                UpdateView();

                Toast.MakeText(Application.Context, DefaultSettings, ToastLength.Short).Show();
            }
        }
示例#3
0
        private async Task OnWork()
        {
            settings = Settings.Instance;
            bool serviceRun = HearServices.IsServiceRunning(typeof(NotifyService), context);

            if (serviceRun)
            {
                partLoad.Start(settings.UpdateTimer);
            }
        }
        public override void OnReceive(Context context, Intent intent)
        {
            try
            {
                if (serviceIntentStop == null)
                {
                    serviceIntentStop = new Intent(context, typeof(NotifyService));
                    serviceIntentStop.SetAction(Info.IntentActionStopService);
                }

                if (serviceIntentStart == null)
                {
                    serviceIntentStart = new Intent(context, typeof(NotifyService));
                    serviceIntentStart.SetAction(Info.IntentActionStartService);
                }

                #region Actions
                #region Action Start
                if (Info.IntentActionStartService == intent.Action)
                {
                    if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.O)
                    {
                        context.StartForegroundService(serviceIntentStart);
                    }
                    else
                    {
                        context.StartService(serviceIntentStart);
                    }
                }
                #endregion
                #region Action Stop
                if (Info.IntentActionStopService == intent.Action)
                {
                    context.StopService(serviceIntentStop);
                }
                #endregion
                #region Action Restart
                if (Info.IntentActionRestartServiceRam == intent.Action)
                {
                    context.StopService(serviceIntentStop);

                    if (!HearServices.IsServiceRunning(typeof(NotifyService), context))
                    {
                        if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.O)
                        {
                            context.StartForegroundService(serviceIntentStart);
                        }
                        else
                        {
                            context.StartService(serviceIntentStart);
                        }
                    }
                }
                #endregion
                #region Action Update
                if (Info.IntentActionUpdateSettings == intent.Action)
                {
                    if (HearServices.IsServiceRunning(typeof(NotifyService), context))
                    {
                        if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.O)
                        {
                            context.StartForegroundService(serviceIntentStart);
                        }
                        else
                        {
                            context.StartService(serviceIntentStart);
                        }
                    }
                }
                #endregion
                #endregion
            }
            catch (Exception ex)
            {
                #region Logging
                LogRuntimeAttribute.InLogFiles(typeof(NotifyReceiver), ex);
                #endregion
            }
            finally { }
        }