Reputation: 3776
I want to build a "Launcher App" to run on my Windows 10 IoT (Raspberry Pi 3) build 14986 (or later). The launcher app should basically just have two buttons to launch (or switch to) other apps already deployed on the device. I'm wonder if anyone knows how to launch an app (from C#)?
I've looked at the Windows.System.Launcher.LaunchUriAsync
API, but I'm not sure what to pass in (I've tested with some URIs and TargetApplicationPackageFamilyName
under options, no luck (nothing happens when calling the method).
Example (which doesn't work):
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);
});
}
Upvotes: 4
Views: 1772
Reputation: 236
You can find the answer on Microsoft Code. There is a sample for that:
https://code.msdn.microsoft.com/windowsapps/How-to-launch-an-UWP-app-5abfa878
In this example you find the Launcher Code:
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();
}
}
The trick is set specify Windows Protocol on the application you want to launch, and specify that in the LaunchApp URI.
Upvotes: 4