2014-04-23 50 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

相關問題