2017-11-25 4 views
0

정기적 인 tost 알림을 만들고 싶지만 snoozeInterva가 "연기"일 뿐이므로 잘못된 해결책을 발견했습니다.정기 Toastnotification UWP

코드 : 그런 다음

public sealed partial class MainPage : Page 
{ 
    const string TOAST = @" 
         <toast> 
          <visual> 
          <binding template=""ToastTest""> 
           <text>Hello Toast</text> 
          </binding> 
          </visual> 
          <audio src =""ms-winsoundevent:Notification.Mail"" loop=""true""/> 
         </toast>"; 

    public MainPage() 
    { 
     this.InitializeComponent(); 
    } 

    private void btnNotification_Click(object sender, RoutedEventArgs e) 
    { 
     var when = DateTime.Now.AddSeconds(6); 
     var offset = new DateTimeOffset(when); 

     Windows.Data.Xml.Dom.XmlDocument xml = new Windows.Data.Xml.Dom.XmlDocument(); 
     xml.LoadXml(TOAST); 
     ScheduledToastNotification toast = new ScheduledToastNotification(xml, offset, TimeSpan.FromSeconds(60), 5); 
     toast.Id = "IdTostone"; 
     toast.Tag = "NotificationOne"; 
     ToastNotificationManager.CreateToastNotifier().AddToSchedule(toast); 
    } 
} 

가 .. 어떻게 13:00에 매일 예를 들어, 정기 토스트 알림을 만들 수 있습니까?

미리 감사드립니다.

답변

1

불행히도이를 수행하는 편리한 방법은 없습니다. 토스트를 매일 같이 보내야 할 경우 토스트 알림을 하루 일정으로 미리 예약 할 수 있습니다. 그런 다음 모든 토스트의 시간을 변경해야한다면 ToastNotificationManager 클래스를 사용하여 토스트 스케쥴에서 토스트 스케쥴을 모두 제거하고 적절한 시간에 새로운 예정 토스트를 만듭니다. 이 같은

뭔가 :

private void ScheduleToast(DateTime scheduledTime) 
    { 
     const string TOAST = @" 
        <toast> 
         <visual> 
         <binding template=""ToastTest""> 
          <text>Hello Toast</text> 
         </binding> 
         </visual> 
         <audio src =""ms-winsoundevent:Notification.Mail"" loop=""true""/> 
        </toast>"; 

     Windows.Data.Xml.Dom.XmlDocument xml = new Windows.Data.Xml.Dom.XmlDocument(); 
     xml.LoadXml(TOAST); 

     ScheduledToastNotification toast = new ScheduledToastNotification(xml, scheduledTime); 
     toast.Id = "IdTostone" + scheduledTime.ToString(); 
     toast.Tag = "NotificationOne"; 
     toast.Group = "MyEverydayToasts"; 
     ToastNotificationManager.CreateToastNotifier().AddToSchedule(toast); 
    } 

    private void RescheduleToastsForTheNextDays(TimeSpan timeOfDay, int nDays = 30) 
    { 
     ToastNotifier toastNotifier = ToastNotificationManager.CreateToastNotifier(); 
     IReadOnlyList<ScheduledToastNotification> scheduledToasts = toastNotifier.GetScheduledToastNotifications(); 
     foreach(ScheduledToastNotification toast in scheduledToasts) 
      toastNotifier.RemoveFromSchedule(toast); 

     for (int i=0; i<nDays; i++) 
     { 
      DateTime scheduledTime = DateTime.Today + timeOfDay + TimeSpan.FromDays(i); 

      if (scheduledTime > DateTime.Now) 
       ScheduleToast(scheduledTime); 
     } 
    } 
+0

내가 평범한 조금 ... 평일 알람이 이런 식으로 구성되어 반복, 창문 시간 응용 프로그램 좋아하니 경우에도 질문을 하시겠습니까? 나는 그에게 아이디어를 분명히 해달라고 부탁한다. 도움을 주셔서 감사합니다. – LightGreen

+0

@ LightGreen 네, 좋다고 생각합니다. 아마도 완벽하지는 않습니다. –

+0

또 다시 고마워요 .. 도움이 .. – LightGreen