[英]Lock Screen (Background) Notification - UWP
我測試吐司下面下面的代碼通知這個:
public static void ShowToastNotification(string message)
{
ToastContent content = new ToastContent()
{
Visual = new ToastVisual()
{
BindingGeneric = new ToastBindingGeneric()
{
Children =
{
new AdaptiveText()
{
Text = message
}
}
}
}
};
ToastNotificationManager.CreateToastNotifier().Show(new ToastNotification(content.GetXml()));
}
清單如下所示:
<VisualElements>
...
<uap:LockScreen BadgeLogo="Assets\BadgeLogo.png" Notification="badgeAndTileText"/>
...
</VisualElements>
...
<BackgroundTasks>
...
<Task Type="pushNotification"/>
...
</BackgroundTasks>
但是當屏幕鎖定時它永遠不會彈出。
當我在幾秒鍾內解鎖時,我可以看到它。
如果我在大約 15 秒后解鎖,我將看不到通知,因為我將持續時間設置為短。
我檢查了以下設置:
我在包清單中聲明后台任務時啟用了推送通知,
我在 Windows 設置中打開了“在鎖定屏幕上顯示通知” ,
我讓我的應用程序在 Windows 設置中在后台運行。
我可以看到它命中了后台任務(因為后台工作中的其他功能)。
我錯過了什么??
如果有辦法更改 WELCOME MESSAGE,那也適用於我。
我正在尋找一種在登錄期間發生錯誤時通知用戶的方法。
任何幫助表示贊賞:)
我為 UWP Windows 應用程序嘗試了這段代碼,它運行良好,您只需要創建一個通用函數
using Windows.UI.Notifications;
public static void ShowToastNotification(string title, string stringContent)
{
ToastNotifier ToastNotifier = ToastNotificationManager.CreateToastNotifier();
Windows.Data.Xml.Dom.XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);
Windows.Data.Xml.Dom.XmlNodeList toastNodeList = toastXml.GetElementsByTagName("text");
toastNodeList.Item(0).AppendChild(toastXml.CreateTextNode(title));
toastNodeList.Item(1).AppendChild(toastXml.CreateTextNode(stringContent));
Windows.Data.Xml.Dom.IXmlNode toastNode = toastXml.SelectSingleNode("/toast");
Windows.Data.Xml.Dom.XmlElement audio = toastXml.CreateElement("audio");
audio.SetAttribute("src", "ms-winsoundevent:Notification.SMS");
ToastNotification toast = new ToastNotification(toastXml);
toast.ExpirationTime = DateTime.Now.AddSeconds(4);
ToastNotifier.Show(toast);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.