c# - UWP 应用无法完全启动另一个 UWP 应用?

标签 c# windows uwp windows-10 windows-10-universal

我正在开发的 UWP 应用程序使用 Launcher 来启动我也编写的另一个 UWP 应用程序。这是我用来启动其他应用程序的代码:

        var uriToLaunch = "testapp-mainpage://";

        var uri = new Uri(uriToLaunch);

        bool success = await Windows.System.Launcher.LaunchUriAsync(uri);

到目前为止,此代码能够启动我编写的其他应用程序,但它只会打开带有中间 X 的默认蓝色背景的应用程序窗口,基本上是默认的 UWP 初始屏幕。我已尝试将 URI 设置为以应用程序的 MainPage 为目标,但无论我如何尝试修改 URI,它都只会启动到默认启动画面。我要启动的应用目前只是一个非常基本的默认 UWP 应用。我错过了什么或做错了什么,因为正在启动的应用程序没有完全初始化?

最佳答案

您需要修改启动的应用程序以处理协议(protocol)激活。默认向导生成一个 app.xaml.cs,它通过 OnLaunched 处理典型激活,但不通过 OnActivated 处理替代激活:

protected override void OnActivated(IActivatedEventArgs args)
{
    if (args.Kind == ActivationKind.Protocol)
    {
        ProtocolActivatedEventArgs eventArgs = args as ProtocolActivatedEventArgs;
        // TODO: Handle URI activation
        // The received URI is eventArgs.Uri.AbsoluteUri

        // You'll likely want to navigate to a page based on AbsoluteUri
        // If you just want to launch the main page you can call essentially
        // the same code as OnLaunched
    }
}

参见 Handle URI activation在 MSDN 上了解更多详细信息。查看Association Launching Sample举个具体的例子。

关于c# - UWP 应用无法完全启动另一个 UWP 应用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40751599/

相关文章:

windows - 是否可以更改每台计算机的 Eclipse 工作空间路径

php - 在 Windows 上从 PHP 运行 Grunt 命令

logging - Windows 10 UWP 应用程序的记录器

c# - 如何设置 Windows.Web.Http.HttpRequestMessage HttpVersion?

c# - 在 UWP 中保存图像时访问被拒绝。访问被拒绝。 (HRESULT : 0x80070005 (E_ACCESSDENIED)) 的异常

c# - 如何删除Point结构的值?

c# - 从 Windows Server 2008 上的 C# .NET 应用程序启动 MapPoint 2006/2011 时出错

c# - 如何让角色扮演游戏中的生物相互追踪

c# - 如何更改 C# StringBuilder.AppendLine 行结尾?

java - SWT在windows上哪里写dll文件?