在Windows Phone 8.1中创建每日Toast通知

时间:2015-02-15 11:27:06

标签: c# notifications windows-phone-8.1 scheduled-tasks

我正在使用C#开发Windows phone 8.1(不是silverlight),我想创建一个Toast通知,每隔一小时(总共10小时,每天10次通知)和每天(10 *每天)显示内容。 这是我用来创建通知的代码

public void ToastNotification()
        {
            ToastTemplateType toastTemplate = ToastTemplateType.ToastText02;
            XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate);

            XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text");            
            toastTextElements[0].AppendChild(toastXml.CreateTextNode("Water to drink: "+ waterRemain));

          //  XmlNodeList toastImageAttributes = toastXml.GetElementsByTagName("image");
          //  ((XmlElement)toastImageAttributes[0]).SetAttribute("src", "ms-appx:///assets/Info.png");
          //  ((XmlElement)toastImageAttributes[0]).SetAttribute("alt", "Smiling Kidney");

            IXmlNode toastNode = toastXml.SelectSingleNode("/toast");
            XmlElement audio = toastXml.CreateElement("audio");

            audio.SetAttribute("src", "ms-winsoundevent:Notification.IM");

            toastNode.AppendChild(audio);

            ((XmlElement)toastNode).SetAttribute("launch", "{\"type\":\"toast\",\"param1\":\"12345\",\"param2\":\"67890\"}");

            Int16 startTimeInHours = 1;
            startTime = DateTime.Now.AddHours(startTimeInHours);

            ScheduledToastNotification recurringToast = new ScheduledToastNotification(toastXml, startTime);
            recurringToast.Id = "Recurring_Toast";

            ToastNotificationManager.CreateToastNotifier().AddToSchedule(recurringToast);

        }

现在我如何每天发出一个祝酒通知,每天应该显示10个通知?

0 个答案:

没有答案