private void InitializePhoneApplication()
{
if (phoneApplicationInitialized)
return;
// Create the frame but don't set it as RootVisual yet; this allows the splash
// screen to remain active until the application is ready to render.
RootFrame = new PhoneApplicationFrame();
RootFrame.Navigated += CompleteInitializePhoneApplication;
// Assign the URI-mapper class to the application frame.
RootFrame.UriMapper = new AssociationUriMapper();
// Handle navigation failures
RootFrame.NavigationFailed += RootFrame_NavigationFailed;
// Ensure we don't initialize again
phoneApplicationInitialized = true;
}
AssociationUriMapper 的实现
using System;
using System.IO;
using System.Windows.Navigation;
using Windows.Phone.Storage.SharedAccess;
namespace sdkAutoLaunch
{
class AssociationUriMapper : UriMapperBase
{
private string tempUri;
public override Uri MapUri(Uri uri)
{
tempUri = uri.ToString();
// File association launch
if (tempUri.Contains("/FileTypeAssociation"))
{
// Get the file ID (after "fileToken=").
int fileIDIndex = tempUri.IndexOf("fileToken=") + 10;
string fileID = tempUri.Substring(fileIDIndex);
// Get the file name.
string incomingFileName =
SharedStorageAccessManager.GetSharedFileName(fileID);
// Get the file extension.
string incomingFileType = Path.GetExtension(incomingFileName);
// Map the .sdkTest1 and .sdkTest2 files to different pages.
switch (incomingFileType)
{
case ".sdkTest1":
return new Uri("/sdkTest1Page.xaml?fileToken=" + fileID, UriKind.Relative);
case ".sdkTest2":
return new Uri("/sdkTest2Page.xaml?fileToken=" + fileID, UriKind.Relative);
default:
return new Uri("/MainPage.xaml", UriKind.Relative);
}
}
// Otherwise perform normal launch.
return uri;
}
}
}
导航页面中获取参数的方法
// Get a dictionary of URI parameters and values.
IDictionary queryStrings = this.NavigationContext.QueryString;
当你获取到共享文件的Token后你就可以从共享存储空间通过 GetSharedFileName文件名称(包括文件在拓展名)和 CopySharedFileAsync 将共享文件拷贝到Target应用的隔离存储区
private void InitializePhoneApplication()
{
if (phoneApplicationInitialized)
return;
// Create the frame but don't set it as RootVisual yet; this allows the splash
// screen to remain active until the application is ready to render.
RootFrame = new PhoneApplicationFrame();
RootFrame.Navigated += CompleteInitializePhoneApplication;
// Assign the URI-mapper class to the application frame.
RootFrame.UriMapper = new AssociationUriMapper();
// Handle navigation failures
RootFrame.NavigationFailed += RootFrame_NavigationFailed;
// Ensure we don't initialize again
phoneApplicationInitialized = true;
}
AssociationUriMapper 和 文件的稍有不同
using System;
using System.Windows.Navigation;
namespace sdkAutoLaunch
{
class AssociationUriMapper : UriMapperBase
{
private string tempUri;
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;
}
}
}
同样在Target app 的 target page的OnNavigatedTo事件中获取参数
// Get a dictionary of URI parameters and values.
IDictionary queryStrings = this.NavigationContext.QueryString;
ProximityDevice device = ProximityDevice.GetDefault();
// Make sure NFC is supported
if (device != null)
{
long Id = device.PublishUriMessage(new System.Uri("contoso:NewProducts"));
Debug.WriteLine("Published Message. ID is {0}", Id);
// Store the unique message Id so that it
// can be used to stop publishing this message
}
LaunchUriAsync 不仅仅可以Launch其他应用 同样可以唤起URL Email 和各种Setting 以及 WindowsPhone应用商店中的内容
详细内容 :http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj662937(v=vs.105).aspx
应用的关联可以是
邮件的附件
IE浏览器中的一个文件
或者是一个NFC的Tag标签
一个应用程序的共享文件
系统保留的文件类型和scheme name 列表
请参考:
http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj207065(v=vs.105).aspx