【问题标题】:Send a Toast Notification from windows universal Application从 Windows 通用应用程序发送 Toast 通知
【发布时间】:2015-02-20 05:46:47
【问题描述】:

我正在尝试找到一种从 Windows 通用应用程序发送 toast 通知的方法。 Azure 文档确实提到了从控制台应用程序执行此操作的方法。不过,这不符合我的用例,我想从 Windows 通用应用程序发送 toast 通知。问题是 nugget 包 Microsoft.Azure.Service.Bus 与 windows 商店或 windows phone 8.1 application 不兼容。

是否有任何 Windows Azure 库允许我从 Windows 通用应用程序发送toast notification

【问题讨论】:

    标签: windows-runtime windows-phone windows-store-apps windows-phone-8.1 win-universal-app


    【解决方案1】:

    通常您不会从 Universal 应用发送 toast。您可以将 toast 发送到应用程序,让用户知道服务器上发生了一些事情。

    如果您想安排从应用程序到本地系统的 toast,那么您不需要 Azure(或其他 Web 服务)。您可以使用预定通知直接安排。见Quickstart: Sending a toast notification (XAML)How to schedule a toast notification (XAML)

    如果你想在其他地方推送通知,那么你可以设置一个 Azure 通知中心,并通过 HttpClient 类通过其REST service 连接到它。

    更常见的是,您的应用会联系您的后端服务器以连接到通知中心。这可以通过 Azure 移动服务轻松设置。见Add push notifications to your Mobile Services app

    【讨论】:

    • 感谢您的回答,我想确认没有遗漏的 API 表单 MSFT。似乎没有...根据您的回答,我需要创建一个 REST 客户端,或者创建一个 Web 服务。
    【解决方案2】:

    以下两个基本示例:

    仅示例 1 文本

    const ToastTemplateType toastTemplate = ToastTemplateType.ToastText01;
    var toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate);
    
    var toastTextElements = toastXml.GetElementsByTagName("text");
    toastTextElements[0].AppendChild(toastXml.CreateTextNode("Hello World!"));
    
    var toast = new ToastNotification(toastXml);
    ToastNotificationManager.CreateToastNotifier().Show(toast);
    

    示例 2 文本和图像

    const ToastTemplateType toastTemplate = ToastTemplateType.ToastImageAndText01;
    var toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate);
    
    var toastTextElements = toastXml.GetElementsByTagName("text");
    toastTextElements[0].AppendChild(toastXml.CreateTextNode("Hello World!"));
    
    var toastImageAttributes = toastXml.GetElementsByTagName("image");
    ((XmlElement)toastImageAttributes[0]).SetAttribute("src", "https://i.stack.imgur.com/wzdIt.jpg");
    
    var toast = new ToastNotification(toastXml);
    ToastNotificationManager.CreateToastNotifier().Show(toast);
    

    【讨论】:

    • 我正在尝试将 toast 通知从一台设备发送到大量设备。此答案只会将通知发送到正在运行该应用的设备。
    • 抱歉,toast notificationpush notification 的问题不清楚。
    【解决方案3】:

    Toast 通知是在屏幕上显示几秒钟的小弹出窗口。它们传达信息,甚至可以自定义播放不同的声音。

    请参阅Windows Universal Apps notifications sample 了解更多信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-25
      • 2015-04-20
      • 2014-09-17
      • 1970-01-01
      • 2022-06-16
      • 2016-10-29
      • 1970-01-01
      相关资源
      最近更新 更多