File associations
File associations allow your app to automatically launch when the user wants to open a particular file. That file could come from a variety of sources including, but not limited to:
- an email attachment
- a website via Internet Explorer
- a Near Field Communications (NFC) tag
- another app from the Store
To register for a file association, you must edit WMAppManifest.xml using the XML (Text) Editor. In Solution Explorer, right-click the WMAppManifest.xml file, and then click Open With. In the Open With window, selectXML(Text) Editor, and then click OK.
<Extensions> <FileTypeAssociation Name="Windows Phone SDK test file type" TaskID="_default" NavUriFragment="fileToken=%s"> <Logos> <Logo Size="small" IsRelative="true">Assets/sdk-small-33x33.png</Logo> <Logo Size="medium" IsRelative="true">Assets/sdk-medium-69x69.png</Logo> <Logo Size="large" IsRelative="true">Assets/sdk-large-176x176.png</Logo> </Logos> <SupportedFileTypes> <FileType ContentType="application/sdk">.sdkTest1</FileType> <FileType ContentType="application/sdk">.sdkTest2</FileType> </SupportedFileTypes> </FileTypeAssociation></Extensions>
Listening for a file launch
When your app is launched to handle a particular file type, a deep link URI is used to take the user to your app. Within the URI, the FileTypeAssociation string designates that the source of the URI is a file association and the fileToken parameter contains the file token. For example, the following code shows a deep link URI from a file association.
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; } } }
more info :
http://msdn.microsoft.com/library/windows/apps/jj206987(v=vs.105).aspx
Enjoy!
Aucun commentaire:
Enregistrer un commentaire