トーストとタイルの通知を実装したい。通知は、アプリが閉じられたときに実行できる必要があるなど、いくつかの基準を満たす必要があります。たとえば、アプリを閉じたときに、誕生日リマインダーをバックグラウンドで実行できます。
私が見つけたサンプル:
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();
}
しかし、私は何の通知も受け取りません。アプリが実行されていないときに機能する通知を設定する方法を誰か教えてもらえますか?