简体   繁体   English

如何以编程方式删除在锁定屏幕中启动的UWP吐司通知?

[英]How can I programatically remove a UWP toast notification that was launched while in lock screen?

I'm launching a toast notification either from the background or in the foreground. 我正在从后台或前台启动烤面包通知。 When the notification was launched while the app is in the foreground, I can hide the notification using: 当应用程序在前台运行时启动通知时,我可以使用以下方法隐藏通知:

_ToastNotifier.Hide(notification);

But when the notification was launched from the background, it doesn't hide the notification from the screen and it keeps ringing the alert. 但是,当通知是从后台启动时,它不会在屏幕上隐藏该通知,并且会不断响起警报。 I wish I can hide the notification when app is activated. 我希望我可以在激活应用程序时隐藏通知。

Also, removing using ToastNotificationManager.History.Remove(tag); 另外,使用ToastNotificationManager.History.Remove(tag);删除ToastNotificationManager.History.Remove(tag); didn't work for me. 没有为我工作。

To see it fail, do the following: 要查看失败,请执行以下操作:

  1. Run the app. 运行应用程序。

  2. Make the tablet sleep(start menu>power>sleep or use the sleep button in the tablet). 使数位板进入睡眠状态(“开始”菜单>“电源”>“睡眠”或使用数位板中的“睡眠”按钮)。

  3. Wake the tablet. 唤醒平板电脑。

  4. While in the lock screen, send a notification from a different device/server to the app. 在锁定屏幕中,将通知从其他设备/服务器发送到应用。

  5. You will hear the notification sound. 您会听到通知声音。

  6. Open the app from the taskbar, don't activate the notification. 从任务栏打开应用程序,不要激活通知。 This is the part where I want to hide the notification, the app is opened and I don't need the notification in the lower right side of the screen. 这是我要隐藏通知的部分,打开了应用程序,并且在屏幕的右下角不需要通知。 The notification will not go away until you tap on it, which is very inconvenient. 直到您点击通知,通知才会消失,这非常不方便。

Update: It doesn't matter if it's in the background or foreground. 更新:是在后台还是在前台都没有关系。 As long as the notification was received while in lock screen". Please see the steps. 只要在锁定屏幕时收到通知即可。”请参阅步骤。

Note that this Toast notofication has a looping audio and scenario="incomingCall". 请注意,此Toast通知具有循环音频和case =“ incomingCall”。

If you want to remove the notification, simply call 如果您要删除通知,只需致电

ToastNotificationManager.History.Remove("tagOfNotification");

You'll have to specify a Tag (and optionally a Group ) on your notification so that you can identify it and remove it. 您必须在通知中指定一个Tag (还可以选择一个Group ),以便标识并删除它。

var toast = new ToastNotification(xml);
toast.Tag = "tag1";

// Send the toast

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

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