我想在我的Windows 10 IoT(Raspberry Pi 3)版本14986(或更高版本)上运行“Launcher App”。启动器应用程序应该基本上只有两个按钮来启动(或切换到)已部署在设备上的其他应用程序。我想知道是否有人知道如何启动应用程序(来自C#)?
我查看了Windows.System.Launcher.LaunchUriAsync
API,但我不知道要传递什么(我在选项下测试了一些URI和TargetApplicationPackageFamilyName
,没有运气(调用时没有任何反应)方法)。
示例(不起作用):
private void button_Click(object sender, RoutedEventArgs e)
{
Task.Run(async () =>
{
var options = new LauncherOptions();
options.TargetApplicationPackageFamilyName = "27ad8aa6-8c23-48bd-9633-e331740e6ba7_mr3ez18jctte6!App";
var uri = new Uri("about:blank");
await Windows.System.Launcher.LaunchUriAsync(uri, options);
});
}
答案 0 :(得分:4)
您可以在Microsoft Code上找到答案。有一个样本:
https://code.msdn.microsoft.com/windowsapps/How-to-launch-an-UWP-app-5abfa878
在此示例中,您可以找到Launcher代码:
private async void RunMainPage_Click(object sender, RoutedEventArgs e)
{
await LaunchAppAsync("test-launchmainpage://HostMainpage/Path1?param=This is param");
}
private async void RunPage1_Click(object sender, RoutedEventArgs e)
{
await LaunchAppAsync("test-launchpage1://Page1/Path1?param1=This is param1¶m1=This is param2");
}
private async Task LaunchAppAsync(string uriStr)
{
Uri uri = new Uri(uriStr);
var promptOptions = new Windows.System.LauncherOptions();
promptOptions.TreatAsUntrusted = false;
bool isSuccess = await Windows.System.Launcher.LaunchUriAsync(uri, promptOptions);
if (!isSuccess)
{
string msg = "Launch failed";
await new MessageDialog(msg).ShowAsync();
}
}
设置技巧,在要启动的应用程序上指定Windows协议,并在LaunchApp URI中指定。