Date post: | 02-Apr-2018 |
Category: |
Documents |
Upload: | edmundo-lozada |
View: | 227 times |
Download: | 0 times |
of 31
7/27/2019 S10 App to App Communication.pdf
1/31
This App
M10: App to App
Communication
async
Andy Wigley | Microsoft Technical Evangelist
Rob Tiffany | Microsoft Enterprise Mobility Strategist
7/27/2019 S10 App to App Communication.pdf
2/31
Target Agenda | Day 1
Module and Topic | 10-minute breaks after each session / 60-minute meal break
1a - Introducing Windows Phone 8 Application Development | Part 1 1b - Introducing Windows Phone 8 Application Development | Part 2
2 - Designing Windows Phone Apps
3 - Building Windows Phone Apps
4 - Files and Storage on Windows Phone 8
Meal Break | 60-minutes
5 - Windows Phone 8 Application Lifecycle
6 - Background Agents
7 - Tiles and Lock Screen Notifications
8 - Push Notifications
9 - Using Phone Resources on Windows Phone 8
7/27/2019 S10 App to App Communication.pdf
3/31
Target Agenda | Day 2
Module and Topic | 10-minute breaks after each session / 60-minute meal break
10 - App to App Communication 11 - Network Communication on Windows Phone 8
12 - Proximity Sensors and Bluetooth
13 - Speech Input on Windows Phone 8
14 - Maps and Location on Windows Phone 8
15 - Wallet Support
16 - In App Purchasing
Meal Break | 60-minutes
17 - The Windows Phone Store
18 - Enterprise Applications in Windows Phone 8: Architecture and Publishing
19 - Windows 8 and Windows Phone 8 Cross Platform Development
20 Mobile Web
7/27/2019 S10 App to App Communication.pdf
4/31
Auto-Launching with File and Protocol Associations
Launching Apps to Handle Particular File Types
Launching one App from Another
Module Agenda
7/27/2019 S10 App to App Communication.pdf
5/31
Auto-Launching with File and
Protocol Associations
12/4/20125
7/27/2019 S10 App to App Communication.pdf
6/31
Auto-launching with File and Protocol Associations
File associations allow your app to launch when the user wants to open a pa
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
special URI
Protocol is the first part of a URI, e.g. myprotocol:/ShowProducts?Categor
Your app launches another and passes it data in the remainder of the laun
7/27/2019 S10 App to App Communication.pdf
7/31
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 orprotocol, 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
7/27/2019 S10 App to App Communication.pdf
8/31
Comparison with Windows 8 User Experience
Like Windows 8, Windows Phone 8 uses
Launcher.LaunchFileAsync(IStorageFile) to launch a file andLauncher.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
http://m/Windows.System.Launcher.LaunchFileAsync(Windows.Storage.IStorageFile).htmhttp://m/Windows.System.Launcher.LaunchUriAsync(Windows.Foundation.Uri).htmhttp://m/Windows.System.Launcher.LaunchUriAsync(Windows.Foundation.Uri).htmhttp://m/Windows.System.Launcher.LaunchUriAsync(Windows.Foundation.Uri).htmhttp://m/Windows.System.Launcher.LaunchUriAsync(Windows.Foundation.Uri).htmhttp://m/Windows.System.Launcher.LaunchFileAsync(Windows.Storage.IStorageFile).htmhttp://m/Windows.System.Launcher.LaunchFileAsync(Windows.Storage.IStorageFile).htmhttp://m/Windows.System.Launcher.LaunchFileAsync(Windows.Storage.IStorageFile).htmhttp://m/Windows.System.Launcher.LaunchFileAsync(Windows.Storage.IStorageFile).htm7/27/2019 S10 App to App Communication.pdf
9/31
Demo 1:
User Experience
7/27/2019 S10 App to App Communication.pdf
10/31
File Associations
7/27/2019 S10 App to App Communication.pdf
11/31
Registering for a File Association
To handle a particular file type, register for a file association in the app man
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
7/27/2019 S10 App to App Communication.pdf
12/31
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
bug-small-33x33.png
bug-medium-69x69.png
bug-large-176x176.png
.bqy
7/27/2019 S10 App to App Communication.pdf
13/31
Listening for a file launch
When your app is launched to handle a file, a deep link URI is sent to your a
/FileTypeAssociation?fileToken=89819279-4fe0-4531-9f57-d633f094
You need to implement a custom URI Mapper to parse the deep link URI an
page in your app that will handle it
FileTypeAssociationdesignates
that the source of the URI is a file type
association
The file token
7/27/2019 S10 App to App Communication.pdf
14/31
Custom URI Mapper - 1
usingSystem;
usingSystem.Windows.Navigation;
usingWindows.Phone.Storage.SharedAccess;
namespaceFileAssociationsHandler
{
classAssociationUriMapper : UriMapperBase
{
privatestringtempUri;
publicoverrideUri 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;
stringfileID = tempUri.Substring(fileIDIndex);
// Get the file name.
stringincomingFileName =
SharedStorageAccessManager.GetSharedFileName(fileID);
...
7/27/2019 S10 App to App Communication.pdf
15/31
Custom URI Mapper - 2
...
// Get the file extension.int extensionIndex = incomingFileName.LastIndexOf('.') + 1;
stringincomingFileType =
incomingFileName.Substring(extensionIndex).ToLower();
// Map the .bqy and .bdp files to the appropriate pages.
switch (incomingFileType)
{
case"bqy":
returnnewUri("/BugQueryPage.xaml?fileToken=" + fileID, UriKind.Relative);
case"bdp":
returnnewUri("/BugDetailPage.xaml?fileToken=" + fileID, UriKind.Relative);
default:returnnewUri("/MainPage.xaml", UriKind.Relative);
}
}
// Map everything else to the main page.
returnnewUri("/MainPage.xaml", UriKind.Relative);
}
}
}
7/27/2019 S10 App to App Communication.pdf
16/31
Using the URI Mapper
Assign the custom URI Mapper to the root frame of the app in App.xaml.cs
privatevoidInitializePhoneApplication()
{
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 = newPhoneApplicationFrame();
RootFrame.Navigated += CompleteInitializePhoneApplication;
// Assign the URI-mapper class to the application frame.
RootFrame.UriMapper = newAssociationUriMapper();
// 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;
}
7/27/2019 S10 App to App Communication.pdf
17/31
Local St
SharedS
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
7/27/2019 S10 App to App Communication.pdf
18/31
Retrieving the File
protectedasyncoverridevoid OnNavigatedTo(NavigationEventArgs e){
// Get a dictionary of URI parameters and values.
IDictionary queryStrings = this.NavigationContext.QueryString;
// Have we been launched to handle a file association?
if (queryStrings.ContainsKey("fileToken"))
{
// Yes we have - get the file token
stringfileToken = queryStrings["fileToken"];
// Copy the file from shared storage
stringfilename = SharedStorageAccessManager.GetSharedFileName(fileToken);IStorageFile bugQueryFile = awaitSharedStorageAccessManager.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 andSharedStorageAccessManager.CopySharedFileAsyncmethods to acc
7/27/2019 S10 App to App Communication.pdf
19/31
Sending a File to Another App
Your app can launch a file so another app can open it
privateasyncvoid 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);
}
7/27/2019 S10 App to App Communication.pdf
20/31
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 re
request will be ignored
See the documentation for a full list of the reserved file types
12/4/201220
7/27/2019 S10 App to App Communication.pdf
21/31
Demo 2:
File Associations
7/27/2019 S10 App to App Communication.pdf
22/31
Protocol Associations
7/27/2019 S10 App to App Communication.pdf
23/31
Protocol Associations
Protocol association allows your app to automatically launch when another
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-ec47ec5b
After the colon, the rest of the URI can be set to whatever you want
7/27/2019 S10 App to App Communication.pdf
24/31
Adding a Protocol Association to WMAppManifest.
To register your app for a protocol association, add a Protocol element in
Extensions element The Extensions element must follow immediately after the Tokens ele
Maximum of 10 protocol associations per app
7/27/2019 S10 App to App Communication.pdf
25/31
Listening for a URI
When your app is launched to handle a protocol association, a deep link UR
your app/Protocol?encodedLaunchUri=contoso:ShowProducts?CategoryID=aea6ae
Implement a custom URI Mapper to parse the deep link URI and map to a p
app that will handle it, same as for File Associations
Protocol designates that the source
of the URI is a protocol associationThe full encoded launch URI
7/27/2019 S10 App to App Communication.pdf
26/31
Launching a URI
Use the LaunchUriAsync method to launch another app that is registered fo
privatevoid Button_Click_1(object sender, RoutedEventArgs e){
// Launch a protocol
Windows.System.Launcher.LaunchUriAsync(newUri("jumpstart:NewSession"));
}
7/27/2019 S10 App to App Communication.pdf
27/31
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 protoc
reservation request will be ignored
See the documentation for a full list of the reserved protocols
7/27/2019 S10 App to App Communication.pdf
28/31
URI scheme Description
http:[URL] Launches the web browser and navigates to the spe
mailto:[email address]Launches the email app and creates a new messageemail address on the To line.Note that the email is not sent until the user taps se
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 AppsUse LaunchUriAsync to launch many of the built-in apps
7/27/2019 S10 App to App Communication.pdf
29/31
Launching Built-in Apps (continued)
URI scheme Description
zune:navigate?appid=[app ID] Launches the Windows Phone Store and shows the dspecified app.
zune:reviewapp Launches the Store and shows the review page for th
zune:reviewapp?appid=[app ID] Launches the Store and shows the review page for th
zune:search?[search parameter]=[value] Launches the Store and searches for the specified co
zune:search?keyword=[search keyword]
&contenttype=app
Launches the Store and searches for apps by keywor
zune:search?publisher=[publisher name] Launches the Store and searches for items by publish
zune:navigate?appid=[app ID]Launches the Windows Phone Store and shows the dspecified app.
zune:reviewapp Launches the Store and shows the review page for th
zune:reviewapp?appid=[app ID] Launches the Store and shows the review page for th
zune:search?[search parameter]=[value] Launches the Store and searches for the specified co
7/27/2019 S10 App to App Communication.pdf
30/31
Summary
App can register to handle particular file types
When the user opens a file from a website, email message or SMS message,launched to process the file
One app can launch another by launching a file of a type for which the seco
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 t
has registered a protocol association
If more than one app has registered the same file or protocol association, th
to select which app should be launched
7/27/2019 S10 App to App Communication.pdf
31/31
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.