Several ways to tune UWP

Original: Several methods to tune UWP

For various reasons, I need to use a WPF program to start a UWP program. Let me summarize it and give myself a backup.

The key to starting a UWP program is the protocol startup

Add a protocol to our UWP app, like this:

Then use the protocol to start the UWP in the following ways:

1. Using UWP's Launcher API

// Create the URI to launch from a string.
var uri = new Uri("protocolname:");

// Launch the URI.
bool success = await Windows.System.Launcher.LaunchUriAsync(uri);

Here is a question: how to use UWP API in WPF, please refer to the link: https://blogs.windows.com/buildingapps/2017/01/25/calling-windows-10-apis-desktop-application/# Zgu8WtZa81OyUzyR.97

2. Use PackageManager, which is also the API of UWP

//var manager = new PackageManager();
//var p = manager.FindPackagesForUser("", PackageId);
//var ls = await p.ToList()[0].GetAppListEntriesAsync();
//foreach (var item in ls)
//{
// await item.LaunchAsync();
//}

Thanks for the careful guidance of the great god vbfool !

Where PackageId is the package family name (PackageFamilyName)

3.使用Process.Start(new ProcessStartInfo("protocolname:"));

4. Use the command line

like: >start myapplication:protocol-parameter, refer to https://docs.microsoft.com/zh-cn/windows/uwp/xbox-apps/automate-launching-uwp-apps#a-nameaccepting-argumentsa to accept parameters

The link also introduces another way: start activation (command line parameters are not supported), which will not be repeated here.

I have been writing WPF for a few months and found that I have forgotten everything about UWP. Hey, such a weak chicken!

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325313076&siteId=291194637