Windows 10 for PC 中的 FindPackagesForCurrentPublisher [英] FindPackagesForCurrentPublisher in Windows 10 for PC

查看:24
本文介绍了Windows 10 for PC 中的 FindPackagesForCurrentPublisher的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以使用或替代 InstallationManager.FindPackagesForCurrentPublisher?好像只适用于手机.

Is there a way to use or an alternative to InstallationManager.FindPackagesForCurrentPublisher? It looks like it is only for the phone.

我知道您可以通过 创建然后启动一个 URI,但我需要知道我要启动的应用程序是否已安装.

I know you can launch an app by creating and then launching a URI, but I need to know if the app I want to launch is installed.

我要发布的应用来自同一发行商.

The app I want to launch is by the same publisher.

推荐答案

如果我们使用 LaunchUriAsync(Uri) 方法来启动一个应用,系统会首先尝试启动注册了这个的已安装应用协议,如果目标应用程序没有安装,那么它会打开商店应用程序并显示注册了该协议的推荐应用程序.

If we use the LaunchUriAsync(Uri) method to launch an app, system will firstly try to launch the installed app which registered this protocol, if the target app is not installed, then it will open the Store app and show the recommended apps which registered this protocol.

FindPackagesForCurrentPublisher 方法只能找到与您的应用具有相同发布者 ID 的应用程序包,对于其他不具有相同发布者的应用,您需要使用 FindPackages 方法,此方法需要<代码>ID_CAP_OEM_DEPLOYMENT.对于桌面,现在没有方法,你需要特殊的权限来做这项工作,否则你无法打破 UWP 应用程序的沙盒.

FindPackagesForCurrentPublisher method can only find the app packages with the same publisher ID as your app, for other app which is not with the same publisher, you will need to use FindPackages method, and this method requires ID_CAP_OEM_DEPLOYMENT. For desktop, there is no method now, you need special access to do that work, otherwise you can't break the sand box of UWP app.

但是,如果您的应用程序不会发布到应用商店中,则有一种方法可以使用 PackageManager 类 以查找已安装的包.要使用此类,您需要像这样将 packageManagement 功能添加到应用程序的清单中:

But if your app won't be published into the Store, there is method which use PackageManager class to find the installed package. To use this class, you will need to add packageManagement capability into your app's manifest like this:

<Package
  xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
  xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
  xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
  xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
  IgnorableNamespaces="uap mp rescap">

  ...

  <Capabilities>
    <Capability Name="internetClient" />
    <rescap:Capability Name="packageManagement" />
  </Capabilities>
</Package>

关于这个能力,你可以参考特殊和受限功能.

For this capability, you can refer to Special and restricted capabilities.

最后你可以在你的应用中使用这个类,例如列出所有已安装的包:

At last you can use this class in your app, for example list all the installed packages:

 var packageManager = new PackageManager();
 IEnumerable<Windows.ApplicationModel.Package> packages = (IEnumerable<Windows.ApplicationModel.Package>)packageManager.FindPackagesForUser("");
 var list = packages.ToList();

这篇关于Windows 10 for PC 中的 FindPackagesForCurrentPublisher的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆