2014-11-25 56 views
0

我使用通用应用程序,其功能之一是在他/她想要的特定时间后向用户发送通知。通知出现时所设置的系统事件(即禁用和启用WiFi)如下来自后台任务的敬酒通知

builder.SetTrigger(new SystemTrigger(SystemTriggerType.NetworkStateChange, false)); 

但与TimeTrigger工作通知没有出现! 这里是我的代码:

var builder = new BackgroundTaskBuilder(); 
     builder.Name = "MyBackgroundTask"; 
     builder.TaskEntryPoint = "SampleWindowsStoreApp.BackgroundTask.MyBackgroundTask"; 

     var _taskbuilder = new TimeTrigger(20, false); 
     builder.SetTrigger(_taskbuilder); 
     builder.Register(); 

知道我能吐司从Package.appxmanifest并宣布定时器和backgroundTask

这是我BackgroundTask代码

public sealed class MyBackgroundTask : IBackgroundTask 
{ 
    public void Run(IBackgroundTaskInstance taskInstance) 
    { 
     var deferral = taskInstance.GetDeferral(); 
     ToastNotificationUtilities.ShowMessage("Hello from the background task. "); 
     deferral.Complete(); 
    } 
} 

我想知道为什么通知20分钟后应该出现不出现。!

回答

0

也许你必须使用类似的是

ToastTemplateType toastTemplate = ToastTemplateType.ToastText02; 

XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate); XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text"); 
toastTextElements[0].AppendChild(toastXml.CreateTextNode("Hello from the background task. ")); ToastNotification toast = new ToastNotification(toastXml); ToastNotificationManager.CreateToastNotifier().Show(toast); 

instand:ToastNotificationUtilities.ShowMessage("Hello from the background task. ")