Windows Phone:在应用程序之间导航

Windows Phone: Navigate between apps

我有一个应用程序,需要在同一部手机中包含指向第二个应用程序的链接。
如果未安装该应用程序,则该链接应指向Windows应用商店进行安装(该部分工作正常)。
但是,如果已安装该应用程序,则该链接应直接指向该应用程序并打开它。我怎样才能做到这一点?
该应用程序有两个版本,一个是WP7,另一个是WP8。如果解决方案与他们不同,请指出差异。

感谢您的帮助...


我相信您想要的是URI关联。您应该能够在WP7应用程序和WP8应用程序中创建不同的关联,并进行相应的处理。

A URI association allows your app to automatically launch when another app launches a special URI.

也请注意:

If you are interested only in launching your own apps, consider using
APIs from the Windows.Phone.Management.Deployment namespace. You can
use this API to check for other apps that you’ve published, and then
launch them if they’re installed.

您基本上只需要更新WMAppManifest.xml文件以包括URI关联,然后侦听该URI。示例:

1
2
3
<Extensions>
  <Protocol Name="contoso" NavUriFragment="encodedLaunchUri=%s" TaskID="_default" />
</Extensions>

然后,您可以使用自定义URI映射器处理关联(上面的顶部链接中的完整示例):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
public override Uri MapUri(Uri uri)
{
   tempUri = System.Net.HttpUtility.UrlDecode(uri.ToString());

   // URI association launch for contoso.
   if (tempUri.Contains("contoso:ShowProducts?CategoryID="))
   {
      // Get the category ID (after"CategoryID=").
      int categoryIdIndex = tempUri.IndexOf("CategoryID=") + 11;
      string categoryId = tempUri.Substring(categoryIdIndex);

      // Map the show products request to ShowProducts.xaml
      return new Uri("/ShowProducts.xaml?CategoryID=" + categoryId, UriKind.Relative);
    }

    // Otherwise perform normal launch.
    return uri;
}

希望这会有所帮助!


您创建的是次要应用吗?如果是这样,请执行以下操作:

1
2
3
4
5
6
7
8
9
10
IEnumerable<Package> packages = InstallationManager.FindPackagesForCurrentPublisher();

foreach (Package package in packages)
{
    if (package.Id.ProductId.ToString().ToLower() =="product id of secondary app")
    {
         //Launch the app
         package.Launch();
    }
}

确保两个应用程序的WMAppManifest中的发布者ID均匹配。

如果此辅助应用程序是由其他人发布的,则需要使用自定义的Uri模式。该应用程序需要开发人员添加此功能,您不能仅启动任何应用程序。