Reputation: 3896
I have Win 10 Universal App which displays toast notifications based on various events within the app.
My problem is that the toast notifications only get displayed when the app is active (it is not minimized to the task bar).
I need the app to display the notifications when I am using any other apps. My settings below:
Toast calling code:
private void DisplayNotification()
{
string toastXmlString = "<toast>"
+ "<visual version='1'>"
+ "<binding template='ToastText04'>"
+ "<text id='1'>Header</text>"
+ "<text id='2'>Line 1</text>"
+ "<text id='3'>Line 2</text>"
+ "</binding>"
+ "</visual>"
+ "</toast>";
Windows.Data.Xml.Dom.XmlDocument toastDOM = new Windows.Data.Xml.Dom.XmlDocument();
toastDOM.LoadXml(toastXmlString);
// Create a toast, then create a ToastNotifier object to show
// the toast
ToastNotification toast = new ToastNotification(toastDOM);
ToastNotificationManager.CreateToastNotifier().Show(toast);
}
Anyone know why this is?
Upvotes: 2
Views: 2088
Reputation: 12465
You need to create a new BackgroundTask for that. There are many solutions available out there, but here is the short list:
Register your task at app startup
if (BackgroundTaskRegistration.AllTasks.Any(task => task.Value.Name == TaskNameConst)) return;
BackgroundTaskBuilder builder = new BackgroundTaskBuilder(); builder.Name = TaskNameConst; builder.TaskEntryPoint = TaskEntryPointConst; builder.SetTrigger(new TimeTrigger(15, false)); builder.Register();
Upvotes: 3