且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

C#UWP启动应用程序

更新时间:2022-12-21 18:38:40

或者,如果还有另一种方法可以检查是否已安装应用程序,请先启动它,然后再将其显示在商店中,以便用户手动安装.

Or, if there is another way to check if App is installed, if it is then launch it, if it is not then show it in store, so user can install it manually.

您可以调用 Launcher.QueryUriSupportAsync 来查看是否已安装该应用程序.此方法将返回 LaunchQuerySupportStatus枚举值,您可以决定通过此值打开应用或Windows存储.

You could call Launcher.QueryUriSupportAsync to see if the app is installed. This method will return LaunchQuerySupportStatus enumeration value, you could decide to open the app or windows store by this value.

请检查以下代码以获取详细信息:

Please check the following code for details:

var ret = await Windows.System.Launcher.QueryUriSupportAsync(new Uri("fb:post?text=foo"), Windows.System.LaunchQuerySupportType.Uri);
if (ret == LaunchQuerySupportStatus.Available)
{
    await Windows.System.Launcher.LaunchUriAsync(new Uri("fb:post?text=foo"));
}
else
{
    await Windows.System.Launcher.LaunchUriAsync(new Uri(@"ms-windows-store://pdp/?ProductId=9wzdncrfj2wl"));
}