Search code examples
windows-phone-8app-hub

FindPackagesForCurrentPublisher and Package.Launch on Windows Phone


I'm looking at making an app which will have the ability to launch on or more of my other existing apps installed by the user on the phone (or direct them to the store).

It sure seems like this is what FindPackagesForCurrentPublisher is for, but I just can't seem to get it to work. To test this out I have my 'hub' app, and two 'target' apps installed. FindPackages... returns the expected list of 3 apps.

As the simplest example I've got code that looks like this:

var packages = InstallationManager.FindPackagesForCurrentPublisher();
// Real code verifies that I'm pointing to the app I want
var package = packages.First();
package.Launch(string.Empty);

However, I always seem to get a error.

  • When running in the emulator, I get AccessViolationException
  • When running on the phone the app just shuts down (even with the debugger attached).

Solution

  • Unfortunately, while it does appear that you can get information about the other installed packages, access to the Package.Launch() API is restricted to apps create by Microsoft and/or Microsoft Partners.

    To solve this problem, I updated the original app to register a URI handler by putting something like this in my WMAppManifest.xml:

    <Extensions>
      <Protocol Name="myapphandler" NavUriFragment="encodedLaunchUri=%s" TaskID="_default" />
    </Extensions>
    

    Then from the hub app that's going to launch it, I can do the following:

    var launcherTask = Launcher.LaunchUriAsync(new Uri("dominionpicker:DominionPickerLauncher")).AsTask();
    launcherTask.Wait();