Toast Notification not working

2020-04-13 05:06发布

Below method executes on call for set Toast, but doesnot display any Toast after time elasped. Is any more setting required for Windows 8 Metro app Toast notification

 int scheduledToastCounter = 1;

    public void Set_Future_Toast()
    {

            XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);

            XmlNodeList stringElements = toastXml.GetElementsByTagName("text");
            stringElements.Item(0).AppendChild(toastXml.CreateTextNode("Scheduled Toast"));

            DateTimeOffset displayTime = DateTimeOffset.UtcNow.AddSeconds(3);

            ScheduledToastNotification scheduledToast = new ScheduledToastNotification(toastXml, displayTime);
            scheduledToast.Id = "Future_" + this.scheduledToastCounter++;

            ToastNotifier notifier = ToastNotificationManager.CreateToastNotifier();
            notifier.AddToSchedule(scheduledToast);

            int scheduledToastCount = notifier.GetScheduledToastNotifications().Count;
        }

     }

7条回答
贼婆χ
2楼-- · 2020-04-13 05:23

Have you tried to make the application Toast Capable? check this thread: Toast notification isn't working?

查看更多
Animai°情兽
3楼-- · 2020-04-13 05:31

You can change directly your Package.appxmanifest from code page :

add ToastCapable to the VisualElements Tag

 <VisualElements  ToastCapable="true">

Some times the screen of the Package.appxmanifest dosen't have the option to change it:

my Package.appxmanifest

查看更多
闹够了就滚
4楼-- · 2020-04-13 05:32

You should set toast capable to yes in app package. enter image description here

查看更多
霸刀☆藐视天下
5楼-- · 2020-04-13 05:33

Be sure that you checked the box in the App's config file to enable Notifications.

查看更多
萌系小妹纸
6楼-- · 2020-04-13 05:35

An interesting issue I ran into is I was using toast with images. I had the images in a dependent assembly with copy to output directory. Scheduling toast just failed silently. Ondemand toast failed with an HRESULT of E_FAIL (no other information). When I finally copied the images into the main project (with copy to output directory) then they started working.

查看更多
贼婆χ
7楼-- · 2020-04-13 05:43

Need set small icon for notifications!!! enter image description here

查看更多
登录 后发表回答