2014-11-25 45 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. ")