2014-04-23 23 views
2

从我WP8后台代理我这是工作的罚款正常ShellToast。发送从后台代理沉默土司的Windows Phone 8.1的Silverlight

但如今随着WP8.1我想给在特定时段(夜间)一个安静的敬酒的能力,它应该只在在这几个小时通知中心显示出来。 我一直在关注this guide,但它似乎并没有在所有的工作。敬酒没有显示出来......

任何人都已经得到了这工作还没有?

感谢

我的代码:

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); 
} 
+1

您是否在清单中启用了Toast通知?否则,有些可能会很酷,因为给定的指南很好,我们不能发布比那里写的更好的代码+解释。 – sibbl

+0

你的意思是ID_CAP_PUSH_NOTIFICATION?没有烤面包,对吧? – robertk

+0

@robertftw请澄清当前代码中哪些内容不起作用。 –

回答

2

谢谢你们!我错过了8.1 SL附带的新Package.appmanifest。旧的ShellToast似乎没有它(我认为?),但没有与新的Toast命名空间。

enter image description here

4

您需要使用新的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,你需要改变WMAP的通知类型pManifest.xml到WNS,否则您的应用程序将无法通过认证。我花了大概一天的时间来解决这个问题,这并不明显。

+0

是的,我正在使用该命名空间。检查我编辑我使用的代码。如果你发现任何错误让我知道。 – robertk

+0

我面临认证问题,我不得不将通知类型更改为WNS。直到我看到你的帖子时,我才会想到:-) – japf

相关问题