Alarm code in Windows Phone 8.1

自闭症网瘾萝莉.ら 提交于 2019-12-07 06:06:26

You can use a scheduled toast notification to fire a toast at a specific time. This doesn't require the app be running when the toast fires, only when the toast is scheduled.

You will need to schedule individual toasts for each day as there is no automatic repetition. If the user is likely to run the app frequently then you can schedule the next 30 days or so whenever the app runs. Another option is to set a MaintainanceTrigger background task to schedule the next 30 days every so often when the app is plugged in.

            // Today, 4:00pm
        DateTime now = DateTime.Now;
        DateTime dueTime = new DateTime(now.Year, now.Month, now.Day, 16, 0, 0);
        ToastNotifier toastNotifier = ToastNotificationManager.CreateToastNotifier();

        for(int i=0;i<30;i++)
        {
            dueTime.AddDays(1);
            XmlDocument toastXml = SetupMyToast(dueTime);

            ScheduledToastNotification scheduledToast = new ScheduledToastNotification(toastXml, dueTime);
            toastNotifier.AddToSchedule(scheduledToast);
        }

For more details see Quickstart: Sending a toast notification (XAML) and How to schedule a toast notification

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!