FindPackagesForCurrentPublisher in Windows 10 for PC

天涯浪子 提交于 2020-01-07 02:23:32

问题


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

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.

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


回答1:


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 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.

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();


来源:https://stackoverflow.com/questions/38721521/findpackagesforcurrentpublisher-in-windows-10-for-pc

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!