S10 App to App Communication

Published on May 2016 | Categories: Types, School Work | Downloads: 35 | Comments: 0 | Views: 235
of 31
Download PDF   Embed   Report

App to App Communication

Comments

Content


This App 
M10: App to App
Communication
 This App await
• async
Andy Wigley | Microsoft Technical Evangelist
Rob Tiffany | Microsoft Enterprise Mobility Strategist
Target Agenda | Day 1
Module and Topic | 10-minute breaks after each session / 60-minute “meal break”
Planned
Duration
1a - Introducing Windows Phone 8 Application Development | Part 1 50:00
1b - Introducing Windows Phone 8 Application Development | Part 2 50:00
2 - Designing Windows Phone Apps 50:00
3 - Building Windows Phone Apps 50:00
4 - Files and Storage on Windows Phone 8 50:00
Meal Break | 60-minutes 60:00
5 - Windows Phone 8 Application Lifecycle 50:00
6 - Background Agents 25:00
7 - Tiles and Lock Screen Notifications 25:00
8 - Push Notifications 30:00
9 - Using Phone Resources on Windows Phone 8 50:00
Target Agenda | Day 2
Module and Topic | 10-minute breaks after each session / 60-minute “meal break”
Planned
Duration
10 - App to App Communication 35:00
11 - Network Communication on Windows Phone 8 50:00
12 - Proximity Sensors and Bluetooth 35:00
13 - Speech Input on Windows Phone 8 35:00
14 - Maps and Location on Windows Phone 8 35:00
15 - Wallet Support 25:00
16 - In App Purchasing 25:00
Meal Break | 60-minutes 60:00
17 - The Windows Phone Store 50:00
18 - Enterprise Applications in Windows Phone 8: Architecture and Publishing 50:00
19 - Windows 8 and Windows Phone 8 Cross Platform Development 50:00
20 – Mobile Web 50:00
• Auto-Launching with File and Protocol Associations
• Launching Apps to Handle Particular File Types
• Launching one App from Another
Module Agenda
Auto-Launching with File and
Protocol Associations

12/4/2012 5
Auto-launching with File and Protocol Associations
• 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
User Experience with File and Protocol Associations
• 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
Comparison with Windows 8 User Experience
• 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
Demo 1:
User Experience
File Associations
Registering for a File Association
• 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



Logo Size Use Dimensions
Small Email attachments 33x33 pixels
Medium Office hub list view 69x69 pixels
Large Browser download 176x176 pixels
Adding a File Association to WMAppManifest.xml
• 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>

Listening for a file launch
• 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
FileTypeAssociation designates
that the source of the URI is a file type
association
The file token

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);
...
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);
}
}
}
Using the URI Mapper
• Assign the custom URI Mapper to the root frame of the app in App.xaml.cs
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;
}
Local Storage
SharedStorage
Accessing the File
• 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
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
Sending a File to Another App
• Your app can launch a file so another app can open it
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);
}
Reserved File Associations
• 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
12/4/2012 20
Demo 2:
File Associations
Protocol Associations
Protocol Associations
• 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




Adding a Protocol Association to WMAppManifest.xml
• 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>

Listening for a URI
• 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
Protocol designates that the source
of the URI is a protocol association
The full encoded launch URI

Launching a URI
• Use the LaunchUriAsync method to launch another app that is registered for that protocol
private void Button_Click_1(object sender, RoutedEventArgs e)
{
// Launch a protocol
Windows.System.Launcher.LaunchUriAsync(new Uri("jumpstart:NewSession"));
}
Reserved Protocol Associations
• 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
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
Launching Built-in Apps (continued)
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.
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.
Summary
• 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

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.

Sponsor Documents

Or use your account on DocShare.tips

Hide

Forgot your password?

Or register your new account on DocShare.tips

Hide

Lost your password? Please enter your email address. You will receive a link to create a new password.

Back to log-in

Close