繁体   English   中英

从Windows Phone 8.1 Silverlight中的后台代理发送无声敬酒

[英]Send silent toast from background agent in Windows Phone 8.1 Silverlight

从我的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);
}

您需要使用新的Windows.UI.Notifications.ToastNotification API。
示例,如何使用它在这里:
http://code.msdn.microsoft.com/wpapps/Action-Center-Quickstart-b15089f2
快速入门文档在这里:
http://msdn.microsoft.com/en-us/library/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 ,否则您的应用程序将无法通过认证。 我花了一天的时间解决这个问题,这并不明显。

多谢你们! 我错过了8.1 SL附带的新Package.appmanifest。 没有它,旧的ShellToast似乎可以工作(我想呢?),但新的Toast命名空间则不能。

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM