【发布时间】:2016-10-23 15:24:04
【问题描述】:
我在通用 Windows 10 上实现了一个 IBackgroundTask,它的工作原理就像一个魅力,但问题是如果发生某些操作,我想启动与该后台任务关联的应用程序。代码很简单:
public sealed class AdvertisementWatcherTask : IBackgroundTask
{
private IBackgroundTaskInstance backgroundTaskInstance;
public void Run(IBackgroundTaskInstance taskInstance)
{
backgroundTaskInstance = taskInstance;
var details = taskInstance.TriggerDetails as BluetoothLEAdvertisementWatcherTriggerDetails;
if (details != null)
{
//Do things
}
}
}
我看到您可以像这样创建 ToastNotification:
Windows.Data.Xml.Dom.XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText01);
Windows.Data.Xml.Dom.XmlNodeList elements = toastXml.GetElementsByTagName("text");
foreach (IXmlNode node in elements)
{
node.InnerText = taskInstance.Task.Name+ " remember to uninstall task if not debugging";
}
ToastNotification notification = new ToastNotification(toastXml);
ToastNotificationManager.CreateToastNotifier().Show(notification);
通知 toast 效果很好。它创建并提示通知,如果您单击它,创建此后台任务的应用程序将启动。这是我想要的行为,但我想启动应用程序而无需单击任何通知。有什么办法可以做到这一点?谢谢。
TL;DR:我想在代码的某个位置启动创建后台任务的应用程序。
【问题讨论】:
-
恐怕目前还没有 API 可以实现您的需求。
标签: windows visual-studio win-universal-app uwp