简体   繁体   English

来自WP7中代码的Toast通知

[英]Toast notification from code in WP7

I want to show toast notification from my app with the code not from push notifications. 我想从我的应用程序显示吐司通知,代码不是来自推送通知。

Like My app was running and I opened the call task and after 5 secs I want to show toast notification on that call screen As My app is running on background and its obscured state. 就像我的应用程序正在运行并且我打开了呼叫任务,并且在5秒后我想在该呼叫屏幕上显示Toast通知因为我的应用程序在后台运行并且其obscured状态。

Here is My Code and I am using Coding4fun toolkit: 这是我的代码,我正在使用Coding4fun工具包:

private void RunBackgroundWorker()
        {
            PhoneCallTask callTask = new PhoneCallTask();
            callTask.PhoneNumber = "03336329631";
            callTask.DisplayName = "Arslan";
            callTask.Show();

            BackgroundWorker backroungWorker = new BackgroundWorker();

            backroungWorker.DoWork += ((s, args) =>
            {
                Thread.Sleep(5000);
            });

            backroungWorker.RunWorkerCompleted += ((s, args) =>
            {
                this.Dispatcher.BeginInvoke(() =>
                {
                    var toast = new ToastPrompt
                    {
                        Title = "Simple usage",
                        Message = "Message",
                        ImageSource = new BitmapImage(new Uri("..\\ApplicationIcon.png", UriKind.RelativeOrAbsolute))
                    };
                    toast.Show();
                }
            );
            });
            backroungWorker.RunWorkerAsync();
        }

You can't run "workers" like this when your app is in suspended state. 当您的应用处于暂停状态时,您无法运行此类“工作人员”。

You can however, run Background Agents - eg periodic agents - http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh202942 但是,您可以运行后台代理 - 例如定期代理 - http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh202942

You also can't show a ToastPrompt using Coding4Fun's library from a Background Agent - but you can use the ShellToast API - see "Toast Notifications for Background Agents" - http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh487170 您也无法使用后台代理中的Coding4Fun库显示ToastPrompt - 但您可以使用ShellToast API - 请参阅“后台代理的Toast通知” - http://msdn.microsoft.com/en-us/library/windowsphone /开发/ hh487170

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM