Loading [MathJax]/jax/output/CommonHTML/config.js
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在wp8前台运行应用时获取吐司通知

如何在wp8前台运行应用时获取吐司通知
EN

Stack Overflow用户
提问于 2016-04-28 13:27:38
回答 2查看 375关注 0票数 1

我想在我的windows phone应用程序中实现"toast“通知。我正在实现推送消息,但我希望它们始终显示。无论应用程序是否正在运行。推送通知将在应用程序关闭时进行处理,但不会在其运行时进行处理。另外,如果我手动创建一个shelltoast,它将不会显示。更困难的是,我不能使用任何外部dll,我只想使用代码。做这件事最好的方法是什么?我已经知道ToastNotificationRecieved事件了。我想知道如何实现它,以便在不使用框架的情况下显示类似于"toast“的消息

我的代码如下

PushPlugin.cs(c#代码)

代码语言:javascript
运行
AI代码解释
复制
public void showToastNotification(string options)
    {

        ShellToast toast;
        if (!TryDeserializeOptions(options, out toast))
        {
            this.DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
            return;
        }
        Deployment.Current.Dispatcher.BeginInvoke(toast.Show);

    }



public void PushChannel_ShellToastNotificationReceived(object sender, NotificationEventArgs e)
        {
 var toast = new PushNotification
            {
                Type = "toast"
            };

            foreach (var item in e.Collection)
            {
                toast.JsonContent.Add(item.Key, item.Value);
            }

            this.ExecuteCallback(this.pushOptions.NotificationCallback, JsonConvert.SerializeObject(toast));
        }

在javascript中

代码语言:javascript
运行
AI代码解释
复制
function onNotificationWP8(data) {
    var pushNotification;
    pushNotification = window.plugins.pushNotification;
    pushNotification.showToastNotification(successHandler, errorHandler,
      {
          "Title": data.jsonContent["wp:Text1"], "Content": data.jsonContent["wp:Text2"], "NavigationUri": data.jsonContent["wp:Param"]
      });

}
EN

回答 2

Stack Overflow用户

发布于 2016-04-28 13:39:13

在未安装Windows Phone 8 Update 3的设备上,当目标应用程序在前台运行时,不会显示吐司通知。在装有Windows Phone 8 Update 3的设备上,当目标应用程序在前台运行时,会显示吐司通知,但会被电话呼叫或锁定屏幕等其他活动所遮挡。

下面的C#代码示例显示了用于使用本地代码创建toast通知的属性。

代码语言:javascript
运行
AI代码解释
复制
// Create a toast notification.
// The toast notification will not be shown if the foreground app is running.
ShellToast toast = new ShellToast();
toast.Title = "[title]";
toast.Content = "[content]";
toast.Show();

这个thread拥有你想要的一切

票数 0
EN

Stack Overflow用户

发布于 2016-05-02 09:04:41

代码语言:javascript
运行
AI代码解释
复制
public static class Notification
{
    public static string ChannelURI = string.Empty;

    public static void MainNotificationCallFunction()
    {
        try
        {
            NotificationMessage("Test Notification");
        }
        catch (Exception e)
        { }
    }

    public static void NotificationMessage(string Message)
    {
        try
        {
            ToastTemplateType toastType = ToastTemplateType.ToastText02;

            XmlDocument toastXmlJob = ToastNotificationManager.GetTemplateContent(toastType);
            XmlNodeList toastTextElementJob = toastXmlJob.GetElementsByTagName("text");
            toastTextElementJob[0].AppendChild(toastXmlJob.CreateTextNode(Message));
            IXmlNode toastNodeJob = toastXmlJob.SelectSingleNode("/toast");
            ((XmlElement)toastNodeJob).SetAttribute("duration", "long");
            ToastNotification toastJob = new ToastNotification(toastXmlJob);
            ToastNotificationManager.CreateToastNotifier().Show(toastJob);
        }
        catch (Exception e)
        { }
    }

    public static void PushNotification()
    {
        try
        {
            /// Holds the push channel that is created or found.
            HttpNotificationChannel pushChannel;
            string channelName = "Usman's Channel";

            // Try to find the push channel.
            pushChannel = HttpNotificationChannel.Find(channelName);

            // If the channel was not found, then create a new connection to the push service.
            if (pushChannel == null)
            {
                pushChannel = new HttpNotificationChannel(channelName);

                //// Register for all the events before attempting to open the channel.
                pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated);
                pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred);
                pushChannel.HttpNotificationReceived += new EventHandler<HttpNotificationEventArgs>(PushChannel_HttpNotificationReceived);

                pushChannel.Open();
                pushChannel.BindToShellTile();
                pushChannel.BindToShellToast();
            }
            else
            {
                //// The channel was already open, so just register for all the events.
                pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated);
                pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred);
                pushChannel.HttpNotificationReceived += new EventHandler<HttpNotificationEventArgs>(PushChannel_HttpNotificationReceived);
            }
        }
        catch (Exception ex)
        { }
    }
    private static void PushChannel_ChannelUriUpdated(object sender, NotificationChannelUriEventArgs e)
    {
        try
        {
            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                // Display the new URI for testing purposes. Normally, the URI would be passed back to your web service at this point.
                System.Diagnostics.Debug.WriteLine(e.ChannelUri.ToString());
                MessageBox.Show(String.Format("Channel Uri is {0}", e.ChannelUri.ToString()));

            });
        }
        catch (Exception ex)
        { }
    }
    private static void PushChannel_ErrorOccurred(object sender, NotificationChannelErrorEventArgs e)
    {
        try
        {
            // Error handling logic for your particular application would be here.
            Deployment.Current.Dispatcher.BeginInvoke(() =>
                MessageBox.Show(String.Format("A push notification {0} error occurred.  {1} ({2}) {3}", e.ErrorType, e.Message, e.ErrorCode, e.ErrorAdditionalData)));
        }
        catch (Exception ex)
        { }
    }
    private static void PushChannel_HttpNotificationReceived(object sender, HttpNotificationEventArgs e)
    {
        try
        {
            string message;
            using (System.IO.StreamReader reader = new System.IO.StreamReader(e.Notification.Body))
            {
                message = reader.ReadToEnd();
            }

            Deployment.Current.Dispatcher.BeginInvoke(() => MessageBox.Show(String.Format("Received Notification {0}:\n{1}", DateTime.Now.ToShortTimeString(), message)));
        }
        catch (Exception ex)
        { }
    }

    private static void channel_ErrorOccurred(object sender, NotificationChannelErrorEventArgs e)
    {
        try
        {
            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                MessageBox.Show(e.Message, "Error", MessageBoxButton.OK);
            });
        }
        catch (Exception ex)
        { }
    }
    private static void channel_ChannelUriUpdated(object sender, NotificationChannelUriEventArgs e)
    {
        try
        {
            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                //ProgressBarPushNotifications.Visibility = System.Windows.Visibility.Collapsed;
                MessageBox.Show(e.ChannelUri.ToString(), "Uri Recieved", MessageBoxButton.OK);
            });
        }
        catch (Exception ex)
        { }
    }
    private static void channel_ShellToastNotificationReceived(object sender, HttpNotificationEventArgs e)
    {
        try
        {
            StringBuilder message = new StringBuilder();
            string relativeUri = string.Empty;

            message.AppendFormat("Received Toast {0}:\n", DateTime.Now.ToShortTimeString());

            using (System.IO.StreamReader reader = new System.IO.StreamReader(e.Notification.Body))
            {
                message.AppendFormat(reader.ReadToEnd());
            }

            // Display a dialog of all the fields in the toast.
            Deployment.Current.Dispatcher.BeginInvoke(() => 
            {
                MessageBox.Show(message.ToString());
            });
        }
        catch (Exception ex)
        { }
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36916160

复制
相关文章
分享几个实用的 chrome 和 edge 扩展
话说没有扩展的浏览器是没有灵魂的,之前分享过几篇关于Chrome扩展的文章(微软的edge也是通用的)这里再分享几个实用的扩展:
苏生不惑
2021/12/27
1.5K0
分享几个实用的 chrome 和 edge 扩展
IE=edge,chrome=1的META信息详解
这几天在玩 HTML5 ★ Boilerplate,注意到meta信息中有这么一句:  代码如下: <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">  http-equiv="X-UA-Compatible"这个是IE8的专用标记,是用来指定Internet Explorer 8 浏览器模拟某个特定版本IE浏览器的渲染方式,以此来解决IE浏览器的兼容问题。  例如指定IE8浏览器使用IE6的渲染方式呈现界面。  曾
deepcc
2018/05/16
1.5K0
Edge ,Google Chrome 打不开所有网页
1、打开注册表,增加如下项HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Edge 2、再DWORD(32位)值,命名RendererCodeIntegrityEnabled,值为0 3、重启edge即可。
上善若水.夏
2020/06/16
2.3K0
在Edge中安装Chrome扩展程序
Edge可以安装绝大多数Chrome商店中的扩展, 但Chrome中的谷歌开发App程序, 类似Secure Shell App, 目前是无法安装的, 新版Edge使用了Chrome的Chromium内核, 可以兼容安装Chrome生态中的各种应用程序,为Edge未来的发展带来了无限可能~
zhaoolee
2019/05/31
3.2K0
基于chrome内核的微软Edge浏览器~
1 下载安装Beta版本 下载地址 Windows 欢迎页 macOS 欢迎页 设置选项卡 Windows macOS macOS macOS 2 推荐功能 2.1 集锦 只需要点
JavaEdge
2021/02/22
7880
基于chrome内核的微软Edge浏览器~
绕过Edge、Chrome和Safari的内容安全策略
概述 ---- Web应用中有许多基本的安全机制,其中一个是同源(same-origin)策略机制,该机制规定了应用程序代码可以访问的资源范围。同源策略的基本思想是,源自于某台服务器上的代码只能访问同一台服务器上的web资源。 比如,在Web浏览器上下文中执行的某个脚本,如果其来源服务器为good.example.com,那么它就可以访问同一台服务器上的数据资源。另一方面,根据同源策略的思想,来自evil.example.com的另一个脚本不能访问good.example.com上的任何数据。
奶糖味的代言
2018/04/16
2.6K0
Chrome和Edge远程代码执行0Day漏洞曝光
北京时间4月13日凌晨,安全研究人员Rajvardhan Agarwal在推特上发布了一个可远程代码执行(RCE)的0Day漏洞,该漏洞可在当前版本的谷歌Chrome浏览器和微软Edge上运行。
FB客服
2021/04/16
8220
Chrome和Edge远程代码执行0Day漏洞曝光
Selenium:Chrome、Edge、Firefox、Opera、Safari常用WebDriver下载安装[通俗易懂]
简介:Selenium中运行需要先配置WebDriver,各主流浏览器安装配置大同小异。
全栈程序员站长
2022/10/02
2.2K0
Selenium:Chrome、Edge、Firefox、Opera、Safari常用WebDriver下载安装[通俗易懂]
垃圾满溢检测系统
垃圾满溢检测系统通过python+yolov5网络模型技术,垃圾满溢检测系统对控画面中小区内的垃圾桶进行7*24小时不间断监控,发现垃圾桶溢满周围有堆积物立即触发预警推送给相关人员处理。YOLOv5中在训练模型阶段仍然使用了Mosaic数据增强方法,该算法是在CutMix数据增强方法的基础上改进而来的。CutMix仅仅利用了两张图片进行拼接,而Mosaic数据增强方法则采用了4张图片,并且按照随机缩放、随机裁剪和随机排布的方式进行拼接而成。这种增强方法可以将几张图片组合成一张,这样不仅可以丰富数据集的同时极大的提升网络的训练速度,而且可以降低模型的内存需求。
燧机科技
2023/04/15
8300
垃圾满溢检测系统
微软全新浏览器 Microsoft Edge 比 谷歌 Chrome 好用吗?
微软的IE浏览器是Windows上默认安装的浏览器,大家都用过,在还没有Chrome浏览器的时候没觉得它怎么不好用,直到后来谷歌出了Chrome浏览器,嗯,真香。然后IE的作用就变成了用来下载Chrome浏览器,反正安装新系统后我都是用IE浏览器下载安装Chrome浏览器,然后就彻底把IE忘了。
苏生不惑
2020/02/14
3.1K0
微软全新浏览器 Microsoft Edge 比  谷歌 Chrome 好用吗?
出差(Bellman-Ford算法)
  A 国有 N 个城市, 编号为1…N 。小明是编号为 1 的城市中一家公司的员 工, 今天突然接到了上级通知需要去编号为 N 的城市出差。
别团等shy哥发育
2023/10/17
2880
出差(Bellman-Ford算法)
【日常】edge和chrome浏览器截屏工具快捷键
首先打开开发者工具 使用右键===>检查 就能打开开发者模式 在开发者模式下,快捷键ctrl+shift + p 然后输入截屏,就能看到了
唯一Chat
2022/09/30
8430
【日常】edge和chrome浏览器截屏工具快捷键
Flowportal.Net BPM帮我轻松搞定单次出差+多出差报表的子表单设计
首先要感谢3个人,第1个是宁波的许先生(QQ昵称:木木),他是FlowPortal应用高手,电话指导我如何通过子流程的方式满足客户的需求,不失是一个绝妙的解决方案。第2个是FlowPortal.Net的官方技术支持Ken,帮我使用FlowPortal的自带功能轻松完成客户的需求。最后一个是QQ上的朋友柏先生,他信任我,让我原创的《[URL=http://www.cuiwenyuan.com/shanghai/post/FlowPortal-Plugin-UserSignature.html]原创FlowPortal用户手写签名插件:Signature[/URL]》有机会帮他们的客户快速满足了手写签名的需求。
崔文远TroyCui
2019/02/26
1K0
重磅!谷歌Chrome再添标签组黑魔法,微软Edge瑟瑟发抖
对于极简主义者和收藏家一样,谷歌 Chrome 浏览器带来了一种新的方式来组织标签到 Chrome 标签组。这个功能现在可以在 Chrome 测试版中使用。
程序员小助手
2020/05/18
5100
重磅!谷歌Chrome再添标签组黑魔法,微软Edge瑟瑟发抖
移位溢注:告别靠人品的偏移注入
在Access数据库类型注入的时候,我们获取不到列名(前提是有表名),一般会选择使用偏移注入,但是这种注入方式往往借助的是个人的人品,且步骤繁琐。本文中我们研究了一种新的注入技术让“偏移注入不再需要人品”。 在这里定义这种注入技术为:“移位溢注技术”。它适用于ACCESS和MYSQL(任何版本)。 我们先来看看普通的偏移注入步骤: 1.判断注入点 2.order by 判断长度 3.判断表名 4.联合查询 5.获取表中列数:union select 1,2,3,4,..,* from TABLE 6.开始偏
FB客服
2018/02/23
9450
移位溢注:告别靠人品的偏移注入
2017年度全国出差地图
根据 汇联易 提供的2017年全国差旅出行数据,我们可以绘制出全国城际差旅联系OD图:
IT阅读排行榜
2018/08/17
9090
2017年度全国出差地图
HDOJ 1033 Edge
Problem Description For products that are wrapped in small packings it is necessary that the sheet of paper containing the directions for use is folded until its size becomes small enough. We assume that a sheet of paper is rectangular and only folded along lines parallel to its initially shorter edge. The act of folding along such a line, however, can be performed in two directions: either the surface on the top of the sheet is brought together, or the surface on its bottom. In both cases the two parts of the rectangle that are separated by the folding line are laid together neatly and we ignore any differences in thickness of the resulting folded sheet. After several such folding steps have been performed we may unfold the sheet again and take a look at its longer edge holding the sheet so that it appears as a one-dimensional curve, actually a concatenation of line segments. If we move along this curve in a fixed direction we can classify every place where the sheet was folded as either type A meaning a clockwise turn or type V meaning a counter-clockwise turn. Given such a sequence of classifications, produce a drawing of the longer edge of the sheet assuming 90 degree turns at equidistant places.
谙忆
2021/01/20
4230
HDOJ 1033 Edge
玩转Microsoft Edge
最早是在楠皮教会我怎么用谷歌浏览器的时候接触到浏览器插件这种东西,要不怎么说天下浏览器出谷歌呢,国内好多打着自主研发幌子的浏览器,一看内核,都是chromium,具体就不点名了。 然后,Microsoft Edge(以下简称Edge)在升级到新版以后活脱脱就是个Chrome的翻版,因为用的就是谷歌的内核,Edge也有自己的插件市场,所以,在导入了Chrome的配置之后,我得以完美的从Chrome过度到Edge。
Akilar
2021/06/11
2.1K0
HTML Meta中添加X-UA-Compatible和IE=Edge,chrome=1有什么作用
这是一个文档兼容模式的定义。主要用于加强代码对IE的兼容性,强制IE使用当前本地最新版标准模式渲染或者用chrome内核渲染。
全栈程序员站长
2022/07/08
1.7K0
HTML Meta中添加X-UA-Compatible和IE=Edge,chrome=1有什么作用
点击加载更多

相似问题

网格容器中Chrome与Firefox的溢出差

20

Firefox与Chrome、Edge、Safari之间的渲染差异

127

Chrome中的编辑行为与Firefox或Edge不同

10

使用PDFBox时MS Edge与Chrome中的字体不同

120

底部溢溢100.0 pxl

10
添加站长 进交流群

领取专属 10元无门槛券

AI混元助手 在线答疑

扫码加入开发者社群
关注 腾讯云开发者公众号

洞察 腾讯核心技术

剖析业界实践案例

扫码关注腾讯云开发者公众号
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档