2

从我的 WP8 后台代理中,我得到了正常工作的正常 ShellToast。

但是现在有了 WP8.1,我希望能够在某些时间(晚上)发送安静的祝酒词,它应该只在这些时间出现在通知中心。我一直在关注本指南,但它似乎根本不起作用。吐司没有出现...

任何人已经得到这个工作了吗?

谢谢

我的代码:

public MainPage()
{
    InitializeComponent();
    SendToast();
}

protected override void OnNavigatedFrom(NavigationEventArgs e)
{
    base.OnNavigatedTo(e);
    SendToast();
}

private void SendToast()
{
    // Using the ToastText02 toast template.
    ToastTemplateType toastTemplate = ToastTemplateType.ToastText02;

    // Retrieve the content part of the toast so we can change the text.
    XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate);

    //Find the text component of the content
    XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text");

    // Set the text on the toast. 
    // The first line of text in the ToastText02 template is treated as header text, and will be bold.
    toastTextElements[0].AppendChild(toastXml.CreateTextNode("Heading"));
    toastTextElements[1].AppendChild(toastXml.CreateTextNode("Body"));

    // Set the duration on the toast
    IXmlNode toastNode = toastXml.SelectSingleNode("/toast");
    ((XmlElement)toastNode).SetAttribute("duration", "long");

    // Create the actual toast object using this toast specification.
    ToastNotification toast = new ToastNotification(toastXml);
    toast.ExpirationTime = DateTimeOffset.UtcNow.AddSeconds(3600);

    // Set SuppressPopup = true on the toast in order to send it directly to action center without 
    // producing a popup on the user's phone.
    toast.SuppressPopup = false;

    // Send the toast.
    ToastNotificationManager.CreateToastNotifier().Show(toast);
}
4

2 回答 2

4

您需要使用新的Windows.UI.Notifications.ToastNotification API。
示例,如何使用它在这里:
http
://code.msdn.microsoft.com/wpapps/Action-Center-Quickstart-b15089f2 快速入门文档在这里:http:
//msdn.microsoft.com/en-us/库/windows/apps/xaml/dn631259.aspx

如果您想发送静默通知,只需将 SuppressPopup 属性设置为 true:http:
//msdn.microsoft.com/en-us/library/windows/apps/windows.ui.notifications.toastnotification.suppresspopup.aspx

重要提示- 如果您想在 Silverlight 8.1 应用程序中使用此 API,您需要将WMAppManifest.xml 中的通知类型更改为 WNS,否则您的应用程序将无法通过认证。我花了大约一天时间解决这个问题,这不是很明显。

于 2014-04-23T18:33:47.523 回答
2

多谢你们!我错过了 8.1 SL 附带的新 Package.appmanifest。旧的 ShellToast 似乎可以在没有它的情况下工作(我认为?),但不适用于新的 toast 命名空间。

在此处输入图像描述

于 2014-04-23T20:33:45.297 回答