public override void OnReceive(Context context, Intent intent) { Console.WriteLine("OnReceive_NotificationReceiver"); var bundle = intent.Extras; id = bundle.GetInt("id", -100000); GetAlarmById(); try { if (intent.Action == context.GetString(Resource.String.AlarmOff)) { TurnOffLaterAlarm(); CreateFailedRecord(); if (HelperAndroid.IsApplicationInTheBackground()) { CrossCurrentActivity.Current.Activity?.FinishAffinity(); } } else if (intent.Action == context.GetString(Resource.String.GoOffNow)) { OpenAlarmActivity(context, bundle); } else if (intent.Action == context.GetString(Resource.String.AlarmPreOff)) { alarm.IsTurnOffPreAlarm = true; App.AlarmService.SaveAlarm(alarm); alarm.IsGoOffPreAlarm = true; TurnOffPreAlarm(); if (HelperAndroid.IsApplicationInTheBackground()) { CrossCurrentActivity.Current.Activity?.FinishAffinity(); } } else if (intent.Action == "GoOffPre") { alarm.IsGoOffPreAlarm = true; App.AlarmService.SaveAlarmAtLocal(alarm); alarm.LaterAlarmTime = DateTime.Now.AddSeconds(0.5); AlarmHelper.SetLaterAlarm(alarm); } } catch { } finally { CancelNotification(context, intent); AlarmsViewModel.RefreshAlarmsCommand?.Execute(null); } }
private void SetLaterAlarm(int minutes) { var alarmTime = SetLaterAlarmAndGetLaterAlarmTime(minutes); AlarmHelper.SetLaterAlarm(alarm); //AlarmController.SetLaterAlarmByManager(alarm, (long)diffTimeSpan.TotalMilliseconds); alarmService.SaveAlarmAtLocal(alarm); countDownForFailed.Cancel(); Toast.MakeText(ApplicationContext, CreateDateString.CreateTimeRemainingString(alarmTime), ToastLength.Long).Show(); NotificationAndroid.NotifyLaterAlarm(alarm, Intent); }
protected override void OnUserLeaveHint() { if (IsNotDelayAlarm) { var alarmTime = GetLaterAlarmTimeForNotDelayAlarm(3); AlarmHelper.SetLaterAlarm(alarm); alarmService.SaveAlarmAtLocal(alarm); Toast.MakeText(ApplicationContext, CreateDateString.CreateTimeRemainingString(alarmTime), ToastLength.Long).Show(); FinishAndRemoveTask(); return; } if (!IsFinished) { SetLaterAlarm(5); FinishAndRemoveTask(); } base.OnUserLeaveHint(); }