[UWP] ScheduledToastNotification仅保留5秒钟 [英] [UWP]ScheduledToastNotification remains only for 5 seconds

查看:112
本文介绍了[UWP] ScheduledToastNotification仅保留5秒钟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问候,


我想请你帮忙。这是关于祝酒。


我的Lumia 950 xl上的默认闹钟让我感到恼火,因为音频太大了所以我试图实现自己的闹钟。我已经使用了ScheduledToastNotification,它没有问题(对我而言)。然后大约一个月前Windows更新,我的警报
停止工作。目前我无法找出问题的原因,因为我有混合信息。


出现的问题是:


1。当应用处于后台时,toast不会播放。


2。当它在前台时:


a)它在我的电脑上播放直到我停止它


b)它在模拟器中播放直到我停止它/ p>

c)它在5秒后停止在我的Lumia 950 xl上播放。


目前我试图找出它在5秒后停止的原因在我的Lumia上。我发现在Windows 10(一般情况下)它是默认间隔,之后烤面包消失,可以在PC上设置但是在Lumia上我找不到通过
增加它的方式。


所以我的问题是:


1。是否有可能在Lumia 950 xl上增加该间隔?


2。更新后的内容是否有可能因为我的应用程序突然停止工作?它看起来每次更新后,窗口中的某些内容发生了变化,很难找到更改的内容。




我不得不说我有点失望,因为在最后一次更新Windows之后:


1。一些地铁应用程序在更新后消失,我不得不调查哪一个


2。收音机FM的应用程序消失了,我不得不安装不同,因为我无法安装相同的那个


3。当我在应用程序之间切换或尝试通过cortana登录时,系统似乎有点慢。



在点击按钮后设置通知的方法在下面。


感谢您的建议。


Dusan

 private void CreateNotificationTest( string sound,TimeSpan timeOfDay)
{
XmlDocument content = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);
var textLines = content.GetElementsByTagName(" text");
textLines [0] .InnerText =" Sample Toast App" ;;
textLines [1] .InnerText ="这是一个示例消息。";
IXmlNode toastNode = content.SelectSingleNode(" / toast");

XmlElement audio = content.CreateElement(" audio");
audio.SetAttribute(" src",sound);
audio.SetAttribute(" loop"," true");

toastNode.AppendChild(音频);

XmlElement r = toastNode as XmlElement;
r.SetAttribute(" scenario"," alarm");

for(int i = 0; i< 10; i ++)//设置闹钟时间的数量
{
var time = new DateTime();
var now = DateTime.Now;
if(now.TimeOfDay.CompareTo(timeOfDay)> 0)//当天的时间已经过去
time = now.Date.AddDays(1).Add(timeOfDay);
else
time = now.Date.Add(timeOfDay);
time = time.AddDays(i);

if(time.DayOfWeek == DayOfWeek.Saturday)
继续;
if(time.DayOfWeek == DayOfWeek.Sunday)
继续;

var toastNotifier = ToastNotificationManager.CreateToastNotifier();
var scheduledToast = new ScheduledToastNotification(content,time,TimeSpan.FromSeconds(100),2);

scheduledToast.Id =" 12345" + i;
toastNotifier.AddToSchedule(scheduledToast);
}
}









解决方案

你好Dušan,



这是一个开发人员论坛,所以我们首先关注你的开发相关问题:

当我使用你的代码进行测试时,要么在PC和手机中我无法始终在屏幕上保持吐司(即使在PC上它会在几秒后消失)。 

所以在我看来,作为一种解决方法,你可以保持警报在屏幕上直到用户通过额外步骤解除它。  

除了将"场景"设置为"闹钟"或"提醒"之外,您还需要在"Toast"节点中添加"actions"("snooze"和"dismiss")。 &NBSP;

<?xml version =" 1.0"编码= QUOT; UTF-8英寸?> 
< toast duration =" long" scenario =" alarm">
< visual>
< binding template =" ToastGeneric">
< text>示例Toast App< / text>
< / binding>
< / visual>
< audio src =" ms-winsoundevent:Notification.Looping.Alarm" loop =" true">
< / audio>
< actions>
< action activationType =" system" arguments =" snooze" content ="" />
< action activationType =" system" arguments =" dismiss" content ="" />
< / actions>
< / toast>




有关Windows 10中的吐司通知的更多信息,请参阅此文章。

https://blogs.msdn.microsoft。 com / tiles_and_toasts / 2015/07/02 / adaptive -to-interactive-toast-notifications-for-windows-10 /  



其他方案,例如FM应用程序已被删除。也许您可以在
反馈中心中与我们分享一些建议。



最好的问候,

David


Greetings,

I would like to ask you for help. It is about toasts.

I was annoyed by default alarm on my Lumia 950 xl because audio was too loud so I tried to implement my own alarm. I have used ScheduledToastNotification and it was warking without problems (for me). Then about one month ago windows updated and my alarm stopped working. Currently I am not able to find out the reason of the problem because I have mixed informations.

The problems that appeared are:

1. toast is not playing when app is in background.

2. when it is in foreground:

a) it plays on my PC until I stop it

b) it plays in emulator until I stop it

c) it stops playing on my Lumia 950 xl after 5 seconds.

Currently I am trying to find out the reason why it stops after 5 seconds on my Lumia. I have found that on windows 10 (generally) it is default interval after which toast disappears and it is possible to set it on PC but on Lumia I cannot find the way to increase it.

So my question is:

1. Is it possible to increase that interval on Lumia 950 xl?

2. Is it possible that after update something changed so my app stopped working suddenly? It looks that after updates everytime something changes in windows and it is hard to find out what has changed.

I have to say I am little disappointed because after last windows update:

1. some metro apps disappeard after update and I had to investiage which one

2. app for radio FM disappeared and I had to install different because I was unable to install the same one anymore

3. system seems little bit slower now when I switch between apps or try to log in by cortana.

Method which sets notification after the click on button is below.

Thanks for advice.

Dusan

        private void CreateNotificationTest(string sound, TimeSpan timeOfDay)
        {
            XmlDocument content = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);
            var textLines = content.GetElementsByTagName("text");
            textLines[0].InnerText = "Sample Toast App";
            textLines[1].InnerText = "The is a sample message.";
            IXmlNode toastNode = content.SelectSingleNode("/toast");

            XmlElement audio = content.CreateElement("audio");
            audio.SetAttribute("src", sound);
            audio.SetAttribute("loop", "true");

            toastNode.AppendChild(audio);

            XmlElement r = toastNode as XmlElement;
            r.SetAttribute("scenario", "alarm");

            for (int i = 0; i < 10; i++) // number of alarm times to set
            {
                var time = new DateTime();
                var now = DateTime.Now;
                if (now.TimeOfDay.CompareTo(timeOfDay) > 0) // time in the current day already passed
                    time = now.Date.AddDays(1).Add(timeOfDay);
                else
                    time = now.Date.Add(timeOfDay);
                time = time.AddDays(i);

                if (time.DayOfWeek == DayOfWeek.Saturday)
                    continue;
                if (time.DayOfWeek == DayOfWeek.Sunday)
                    continue;

                var toastNotifier = ToastNotificationManager.CreateToastNotifier();
                var scheduledToast = new ScheduledToastNotification(content, time, TimeSpan.FromSeconds(100), 2);

                scheduledToast.Id = "12345" + i;
                toastNotifier.AddToSchedule(scheduledToast);
            }
        }

解决方案

Hi Dušan,

This is a developer forum so let’s focus on your dev related question first:
When I use your code to test, either in PC and Mobile I cannot keep the toast always on the screen(even on PC it will disappear after some seconds). 
So in my point of view, as a workaround you could keep the alarm on screen until the user dismisses it by additional step.  
Other than only set "scenario" to "alarm" or "reminder", you also need to add "actions" ("snooze" and "dismiss") in the "toast" node. 

<?xml version="1.0" encoding="utf-8" ?>
<toast duration = "long" scenario = "alarm">
  <visual>
    <binding template = "ToastGeneric">
      <text>  Sample Toast App  </text>
    </binding>
  </visual>
  <audio src = "ms-winsoundevent:Notification.Looping.Alarm" loop = "true">
  </audio>
  <actions>
    <action activationType = "system" arguments = "snooze" content = ""/>
    <action activationType = "system" arguments = "dismiss" content = ""/>
  </actions>
</toast>


For more information about toast notification in Windows 10, please refer to this article.
https://blogs.msdn.microsoft.com/tiles_and_toasts/2015/07/02/adaptive-and-interactive-toast-notifications-for-windows-10/ 

For other scenarios, for example FM app was removed. Maybe you can share us some suggestions in the Feedback Hub.

Best Regards,
David


这篇关于[UWP] ScheduledToastNotification仅保留5秒钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆