2017-11-25 8 views
0

定期的なTost通知を作成したいのですが、snoozeIntervaが単に延期に過ぎないため、間違った解決策が見つかりました。定期トーナメント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

私は平日のアラームがこのように構成されて繰り返して、あなたがWindowsタイムアプリが好きですか...でも、少し陳腐な場合は質問をしたいと思いますか?私は彼にアイデアを明確にするよう頼む。助けてくれてありがとう。 – LightGreen

+0

@ LightGreenはい、いいと思います。おそらく完璧ではない。 –

+0

再度お返事ありがとうございます.. – LightGreen

関連する問題