【问题标题】:How to start the app that is associated to the IBackgroundTask I've created in UWP Windows 10如何启动与我在 UWP Windows 10 中创建的 IBackgroundTask 关联的应用程序
【发布时间】: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


【解决方案1】:

您不能以编程方式启动 URI 或从后台任务打开应用程序。但是,您可以显示提醒或 toast 通知,让用户打开您的应用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-02
    相关资源
    最近更新 更多