【问题标题】:Toast Notification From Background Task来自后台任务的 Toast 通知
【发布时间】:2015-06-23 15:17:18
【问题描述】:

我在通用应用程序上工作,它的一个功能是在他/她想要的特定时间后向用户发送通知。将系统事件(即禁用和启用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 启用 Toast 并声明 Timer 和 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 分钟后出现的通知没有出现。!

【问题讨论】:

    标签: windows windows-phone universal


    【解决方案1】:

    也许你必须使用类似的东西

    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);
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-04
      相关资源
      最近更新 更多