我想实现 Toast 和 Tile 通知。我的通知必须满足一些条件,例如它需要能够在我的应用关闭时运行。例如,当应用程序关闭时,生日提醒可以在后台运行。
我发现的样本:
ShellToast toast = new ShellToast();
toast.Title = "Toast Title: ";
toast.Content = "TEST";
toast.Show();
上面的示例在应用程序运行时有效。这是我的代码:
private void StartPeriodicAgent()
{
// Variable for tracking enabled status of background agents for this app.
agentsAreEnabled = true;
// Obtain a reference to the period task, if one exists
periodicTask = ScheduledActionService.Find(periodicTaskName) as PeriodicTask;
// If the task already exists and background agents are enabled for the
// application, you must remove the task and then add it again to update
// the schedule
if (periodicTask != null)
{
RemoveAgent(periodicTaskName);
}
periodicTask = new PeriodicTask(periodicTaskName);
periodicTask.ExpirationTime = System.DateTime.Now.AddDays(1);
// The description is required for periodic agents. This is the string that the user
// will see in the background services Settings page on the device.
periodicTask.Description = "This demonstrates a periodic task.";
// Place the call to Add in a try block in case the user has disabled agents.
ScheduledActionService.Add(periodicTask);
}
private void RunBackgroundWorker()
{
//PhoneCallTask calltask = new PhoneCallTask();
//calltask.PhoneNumber = "03336329631";
//calltask.DisplayName = "arslan";
//calltask.Show();
BackgroundWorker backroungWorker = new BackgroundWorker();
backroungWorker.DoWork += ((s, args) =>
{
Thread.Sleep(10000);
});
backroungWorker.RunWorkerCompleted += ((s, args) =>
{
this.Dispatcher.BeginInvoke(() =>
{
var toast = new ToastPrompt
{
Title = "Simple usage",
Message = "Message"
};
toast.Show();
}
);
});
backroungWorker.RunWorkerAsync();
}
但我没有收到任何通知。谁能告诉我如何设置在应用程序未运行时有效的通知?