我正在开发的 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/