Se ha denunciado esta presentación.
Utilizamos tu perfil de LinkedIn y tus datos de actividad para personalizar los anuncios y mostrarte publicidad más relevante. Puedes cambiar tus preferencias de publicidad en cualquier momento.
Oliver Scheer
Senior Technical Evangelist
Microsoft Deutschland
http://the-oliver.com
File and Protocol
Associations
This ...
Agenda
3/18/2014Microsoft confidential2
Launching Apps to Handle
Particular File Types
Launching one App from
Another
Auto...
• File associations allow your app to launch when the user wants to open a particular file
type, via:
• an email attachmen...
• When a user launches a file or protocol from an app
• If there is only one app on the phone registered for that file or
...
• Like Windows 8, Windows Phone 8 uses
Launcher.LaunchFileAsync(IStorageFile) to launch a file and
Launcher.LaunchUriAsync...
File Associations
3/18/2014Microsoft confidential7
• To handle a particular file type, register for a file association in the app manifest file
• Optionally supply logos tha...
• Add a FileTypeAssociation element inside the Extensions element
• The Extensions element must follow immediately after t...
• When your app is launched to handle a file, a deep link URI is sent to your app
/FileTypeAssociation?fileToken=89819279-...
Custom URI Mapper - 1
using System;
using System.Windows.Navigation;
using Windows.Phone.Storage.SharedAccess;
namespace F...
Custom URI Mapper - 2
...
// Get the file extension.
int extensionIndex = incomingFileName.LastIndexOf('.') + 1;
string in...
Using the URI Mapper
private void InitializePhoneApplication()
{
if (phoneApplicationInitialized)
return;
// Create the fr...
Local Storage
SharedStorage
• Files passed to an app are stored by the OS
in a special folder called SharedStorage
• Recei...
Retrieving the File
protected async override void OnNavigatedTo(NavigationEventArgs e)
{
// Get a dictionary of URI parame...
• Your app can launch a file so another app can open it
Sending a File to Another App
3/18/201416
private async void Launc...
• Many file extensions are reserved for the built-in apps
• .cer, .doc, .docx, .jpg, .mp3, .pptx … etc..
• Many more reser...
Protocol
Associations
3/18/2014Microsoft confidential19
• Protocol association allows your app to automatically launch when another app launches a
special URI
• The URI begins wi...
• To register your app for a protocol association, add a Protocol element inside the Extensions
element
• The Extensions e...
• When your app is launched to handle a protocol association, a deep link URI is sent to
your app
/Protocol?encodedLaunchU...
• Use the LaunchUriAsync method to launch another app that is registered for that protocol
Launching a URI
3/18/201423
pri...
• Some protocols are reserved for the built-in apps
• http:, MailTo:, Map:
• Many more reserved by the OS
• File:, Iehisto...
URI scheme Description
http:[URL]
Launches the web browser and navigates to the specified
URL.
mailto:[email address]
Laun...
Launching Built-in Apps (cont)
3/18/2014Microsoft confidential26
URI scheme Description
zune:navigate?appid=[app ID]
Launc...
• App can register to handle particular file types
• When the user opens a file from a website, email message or SMS messa...
The information herein is for informational
purposes only an represents the current view of
Microsoft Corporation as of th...
Windows Phone 8 - 11 App to App Communication
Windows Phone 8 - 11 App to App Communication
Próxima SlideShare
Cargando en…5
×

Windows Phone 8 - 11 App to App Communication

  • Inicia sesión para ver los comentarios

Windows Phone 8 - 11 App to App Communication

  1. 1. Oliver Scheer Senior Technical Evangelist Microsoft Deutschland http://the-oliver.com File and Protocol Associations This App   This App
  2. 2. Agenda 3/18/2014Microsoft confidential2 Launching Apps to Handle Particular File Types Launching one App from Another Auto-Launching with File and Protocol Associations Automatically launch your app when another app launches a particular file type or protocol File associations allow your app to launch to handle an email attachment, a file opened in Internet Explorer or by another app
  3. 3. • File associations allow your app to launch when the user wants to open a particular file type, via: • an email attachment • a website via Internet Explorer • a text message • a Near Field Communications (NFC) tag • another app from the Store • Protocol association allows your app to automatically launch when another app launches a special URI • Protocol is the first part of a URI, e.g. myprotocol:/ShowProducts?CategoryID=aea6ae1f • Your app launches another and passes it data in the remainder of the launch URI Auto-launching with File and Protocol Associations 3/18/2014Microsoft confidential3
  4. 4. • When a user launches a file or protocol from an app • If there is only one app on the phone registered for that file or protocol, the app is automatically launched • If there is more than one app registered for that file or protocol, the user is asked which app they want to use • If no apps on the phone can handle that file or protocol, the user is given the option to get one that does User Experience with File and Protocol Associations 3/18/2014Microsoft confidential4
  5. 5. • Like Windows 8, Windows Phone 8 uses Launcher.LaunchFileAsync(IStorageFile) to launch a file and Launcher.LaunchUriAsync(Uri) to launch a URI • However, the way Windows Phone XAML apps receive a file or URI is different • Windows 8 has a “default” Store app for a file type or URI, so that will be launched • In Windows Phone 8, if there are multiple Store apps installed that can handle a particular file or protocol association, the user chooses the receiving app from a menu Comparison with Windows 8 User Experience 3/18/2014Microsoft confidential5
  6. 6. File Associations 3/18/2014Microsoft confidential7
  7. 7. • To handle a particular file type, register for a file association in the app manifest file • Optionally supply logos that Windows Phone OS will use when listing files • Edit WMAppManifest.xml using the XML (Text) Editor Registering for a File Association 3/18/2014Microsoft confidential8 Logo Size Use Dimensions Small Email attachments 33x33 pixels Medium Office hub list view 69x69 pixels Large Browser download 176x176 pixels
  8. 8. • Add a FileTypeAssociation element inside the Extensions element • The Extensions element must follow immediately after the Tokens element • Specify up to 20 file extensions per file type association <Extensions> <FileTypeAssociation Name="BugQuery" TaskID="_default" NavUriFragment="fileToken=%s"> <Logos> <Logo Size="small">bug-small-33x33.png</Logo> <Logo Size="medium">bug-medium-69x69.png</Logo> <Logo Size="large">bug-large-176x176.png</Logo> </Logos> <SupportedFileTypes> <FileType>.bqy</FileType> </SupportedFileTypes> </FileTypeAssociation> </Extensions> Adding a File Association to WMAppManifest.xml 3/18/2014Microsoft confidential9
  9. 9. • When your app is launched to handle a file, a deep link URI is sent to your app /FileTypeAssociation?fileToken=89819279-4fe0-4531-9f57-d633f0949a19 • You need to implement a custom URI Mapper to parse the deep link URI and map to a page in your app that will handle it Listening for a file launch 3/18/2014Microsoft confidential10 FileTypeAssociation designates that the source of the URI is a file type association The file token
  10. 10. Custom URI Mapper - 1 using System; using System.Windows.Navigation; using Windows.Phone.Storage.SharedAccess; namespace FileAssociationsHandler { 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); ...
  11. 11. Custom URI Mapper - 2 ... // Get the file extension. int extensionIndex = incomingFileName.LastIndexOf('.') + 1; string incomingFileType = incomingFileName.Substring(extensionIndex).ToLower(); // Map the .bqy and .bdp files to the appropriate pages. switch (incomingFileType) { case "bqy": return new Uri("/BugQueryPage.xaml?fileToken=" + fileID, UriKind.Relative); case "bdp": return new Uri("/BugDetailPage.xaml?fileToken=" + fileID, UriKind.Relative); default: return new Uri("/MainPage.xaml", UriKind.Relative); } } // Map everything else to the main page. return new Uri("/MainPage.xaml", UriKind.Relative); } } }
  12. 12. Using the URI Mapper 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; // Handle reset requests for clearing the backstack RootFrame.Navigated += CheckForResetNavigation; // Ensure we don't initialize again phoneApplicationInitialized = true; } • Assign the custom URI Mapper to the root frame of the app in App.xaml.cs
  13. 13. Local Storage SharedStorage • Files passed to an app are stored by the OS in a special folder called SharedStorage • Receiving apps only have read access to this folder • Copy file to local storage to access it Accessing the File 3/18/201414
  14. 14. Retrieving the File protected async override void OnNavigatedTo(NavigationEventArgs e) { // Get a dictionary of URI parameters and values. IDictionary<string, string> queryStrings = this.NavigationContext.QueryString; // Have we been launched to handle a file association? if (queryStrings.ContainsKey("fileToken")) { // Yes we have - get the file token string fileToken = queryStrings["fileToken"]; // Copy the file from shared storage string filename = SharedStorageAccessManager.GetSharedFileName(fileToken); IStorageFile bugQueryFile = await SharedStorageAccessManager.CopySharedFileAsync( ApplicationData.Current.LocalFolder, // Store in the local folder filename, // keep the same filename NameCollisionOption.ReplaceExisting, // Replace any existing file of the same name fileToken); // Do something with the file... } ... } • Use the SharedStorageAccessManager.GetSharedFileName and SharedStorageAccessManager.CopySharedFileAsync methods to access the file
  15. 15. • Your app can launch a file so another app can open it Sending a File to Another App 3/18/201416 private async void LaunchFileButton_Click(object sender, RoutedEventArgs rea) { // Access local storage. StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder; // Access the bug query file. StorageFile bqfile = await local.GetFileAsync("file1.bqy"); // Launch the bug query file. Windows.System.Launcher.LaunchFileAsync(bqfile); }
  16. 16. • Many file extensions are reserved for the built-in apps • .cer, .doc, .docx, .jpg, .mp3, .pptx … etc.. • Many more reserved by the OS • .ade, .adp ….[ > 100 in total! ] … .xnk • If you try to reserve a file association using one of the reserved types, the reservation request will be ignored • See the documentation for a full list of the reserved file types Reserved File Associations 3/18/2014Microsoft confidential17
  17. 17. Protocol Associations 3/18/2014Microsoft confidential19
  18. 18. • Protocol association allows your app to automatically launch when another app launches a special URI • The URI begins with a protocol name that your app has registered for • For example, contoso is the protocol name in the following URI: contoso:ShowProducts?CategoryID=aea6ae1f-9894-404e-8bca-ec47ec5b9c6c • After the colon, the rest of the URI can be set to whatever you want Protocol Associations 3/18/2014Microsoft confidential20
  19. 19. • To register your app for a protocol association, add a Protocol element inside the Extensions element • The Extensions element must follow immediately after the Tokens element • Maximum of 10 protocol associations per app <Extensions> <Protocol Name=“contoso" TaskID="_default" NavUriFragment=“encodedLaunchUri=%s"> </Extensions> Adding a Protocol Association to WMAppManifest.xml 3/18/2014Microsoft confidential21
  20. 20. • When your app is launched to handle a protocol association, a deep link URI is sent to your app /Protocol?encodedLaunchUri=contoso:ShowProducts?CategoryID=aea6ae1f • Implement a custom URI Mapper to parse the deep link URI and map to a page in your app that will handle it, same as for File Associations Listening for a URI 3/18/2014Microsoft confidential22 Protocol designates that the source of the URI is a protocol association The full encoded launch URI
  21. 21. • Use the LaunchUriAsync method to launch another app that is registered for that protocol Launching a URI 3/18/201423 private void Button_Click_1(object sender, RoutedEventArgs e) { // Launch a protocol Windows.System.Launcher.LaunchUriAsync(new Uri("jumpstart:NewSession")); }
  22. 22. • Some protocols are reserved for the built-in apps • http:, MailTo:, Map: • Many more reserved by the OS • File:, Iehistory:, Javascript:, … many more… • If you try to reserve a protocol association using one of the reserved protocols, the reservation request will be ignored • See the documentation for a full list of the reserved protocols Reserved Protocol Associations 3/18/2014Microsoft confidential24
  23. 23. URI scheme Description http:[URL] Launches the web browser and navigates to the specified URL. mailto:[email address] Launches the email app and creates a new message with the specified email address on the To line. Note that the email is not sent until the user taps send. ms-settings-accounts: Launches the Account Settings app. ms-settings-airplanemode: Launches the Airplane Mode Settings app. ms-settings-bluetooth: Launches the Bluetooth Settings app. ms-settings-cellular: Launches the Cellular Settings app. ms-settings-emailandaccounts: Launches the email and accounts settings app. ms-settings-location: Launches the Location Settings app. ms-settings-lock: Launches the Lock Screen settings app. ms-settings-wifi: Launches the Wi-Fi Settings app. Launching Built-in Apps Use LaunchUriAsync to launch many of the built-in apps 3/18/2014Microsoft confidential25
  24. 24. Launching Built-in Apps (cont) 3/18/2014Microsoft confidential26 URI scheme Description zune:navigate?appid=[app ID] Launches the Windows Phone Store and shows the details page for the specified app. zune:reviewapp Launches the Store and shows the review page for the calling app. zune:reviewapp?appid=[app ID] Launches the Store and shows the review page for the specified app. zune:search?[search parameter]=[value] Launches the Store and searches for the specified content. zune:search?keyword=[search keyword] &contenttype=app Launches the Store and searches for apps by keyword. zune:search?publisher=[publisher name] Launches the Store and searches for items by publisher name.
  25. 25. • App can register to handle particular file types • When the user opens a file from a website, email message or SMS message, your app is launched to process the file • One app can launch another by launching a file of a type for which the second app has registered a file association • App can register for an association with particular URI protocols • One app can launch another by launching a URI using a protocol for which the second app has registered a protocol association • If more than one app has registered the same file or protocol association, the user is asked to select which app should be launched Summary 3/18/2014
  26. 26. The information herein is for informational purposes only an represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

×