【问题标题】:Toast Notification not working吐司通知不起作用
【发布时间】:2015-05-30 06:27:41
【问题描述】:

下面的方法在调用 set Toast 时执行,但在时间过去后不显示任何 Toast。 Windows 8 Metro 应用 Toast 通知是否需要更多设置

 int scheduledToastCounter = 1;

    public void Set_Future_Toast()
    {

            XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);

            XmlNodeList stringElements = toastXml.GetElementsByTagName("text");
            stringElements.Item(0).AppendChild(toastXml.CreateTextNode("Scheduled Toast"));

            DateTimeOffset displayTime = DateTimeOffset.UtcNow.AddSeconds(3);

            ScheduledToastNotification scheduledToast = new ScheduledToastNotification(toastXml, displayTime);
            scheduledToast.Id = "Future_" + this.scheduledToastCounter++;

            ToastNotifier notifier = ToastNotificationManager.CreateToastNotifier();
            notifier.AddToSchedule(scheduledToast);

            int scheduledToastCount = notifier.GetScheduledToastNotifications().Count;
        }

     }

【问题讨论】:

  • 空的catch 块在那里做什么?除了隐藏错误。
  • @CodyGray 我只是在这里忽略了异常处理。但是方法执行没有任何异常。

标签: windows-8 toast microsoft-metro


【解决方案1】:

您应该在应用程序包中将 toast 功能设置为 yes。

【讨论】:

    【解决方案2】:

    确保您选中了应用配置文件中的复选框以启用通知。

    【讨论】:

      【解决方案3】:

      您的对象 notifier 的属性 settings 告诉您为什么无法显示 toast:

      0:启用,可以显示此应用发出的所有通知。

      1:DisabledForApplication,用户已禁用此应用的通知。

      2:DisabledForUser,用户或管理员已禁用此计算机上此用户的所有通知。

      3:DisabledByGroupPolicy,管理员已通过组策略禁用此计算机上的所有通知。组策略设置会覆盖用户的设置。

      4:DisabledByManifest,此应用尚未在其 package.appxmanifest 文件中声明自己支持 toast。此设置可在清单的应用程序 UI 页面的通知部分下找到。对于要发送 toast 的应用,Toast Capable 选项必须设置为“是”。

      http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.notifications.notificationsetting.aspx

      【讨论】:

        【解决方案4】:

        您可以直接从代码页更改您的 Package.appxmanifest :

        将 ToastCapable 添加到 VisualElements 标记

         <VisualElements  ToastCapable="true">
        

        有时 Package.appxmanifest 的屏幕没有更改它的选项:

        【讨论】:

          【解决方案5】:

          需要为通知设置小图标!!!

          【讨论】:

            【解决方案6】:

            您是否尝试过让应用程序 Toast Capable?检查此线程:Toast notification isn't working?

            【讨论】:

              【解决方案7】:

              我遇到的一个有趣的问题是我使用带有图像的 toast。我将图像放在一个依赖程序集中,并复制到输出目录。安排吐司只是默默地失败了。 Ondemand toast 失败,HRESULT 为 E_FAIL(没有其他信息)。当我最终将图像复制到主项目中(复制到输出目录)时,它们开始工作。

              【讨论】:

                猜你喜欢
                • 2014-06-28
                • 1970-01-01
                • 2011-09-24
                • 1970-01-01
                • 2014-10-18
                • 2016-08-23
                • 2012-10-30
                • 2017-05-23
                相关资源
                最近更新 更多