Toast Notification not working

别等时光非礼了梦想. 提交于 2019-12-02 04:09:23

问题


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;
        }

     }

回答1:


You should set toast capable to yes in app package.




回答2:


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




回答3:


The property settings of your object notifier told you why the toast can't be displayed:

0: Enabled, All notifications raised by this app can be displayed.

1: DisabledForApplication, The user has disabled notifications for this app.

2: DisabledForUser, The user or administrator has disabled all notifications for this user on this computer.

3: DisabledByGroupPolicy, An administrator has disabled all notifications on this computer through group policy. The group policy setting overrides the user's setting.

4: DisabledByManifest, This app has not declared itself toast capable in its package.appxmanifest file. This setting is found on the manifest's Application UI page, under the Notification section. For an app to send toast, the Toast Capable option must be set to "Yes".

http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.notifications.notificationsetting.aspx




回答4:


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:




回答5:


Need set small icon for notifications!!!




回答6:


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




回答7:


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.



来源:https://stackoverflow.com/questions/9107177/toast-notification-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!