
Windows 8 Contracts and Extensions

In Windows 8, for metro-style applications, contracts are used to interact with each other , and extensions are used to interact with the system .
There are a lot of various contracts and extensions. To write a post about what contracts and extensions are available to the developer, I was prompted by a Windows 8 article . The “search” contract in detailAfter which I decided to systematize my knowledge and collect in one place short, literally in a few lines, “how to” on most contracts and extensions, with examples from the Windows SDK Samples .
So let's get started. Let's start with the contracts.
Contracts:
- App to App Picking - the ability for one application to directly select files that another application provides;
How to implement File Open Picker Contract:
1) add the File Open Picket Contract (Add Item) element to the project;
2) handle FileOpenPickerActivated;
3) use FileOpenPickerUI.
How to implement File Save Picker Contract:
1) define in the manifest;
2) handle FileSavePickerActivated;
3) use FileSavePickerUI.
An example application that implements File Open and File Save Picker contracts
- Cached File Updater - the ability to control caching of remote content by a local application, as well as updating locally modified cached content to a remote server;
How to implement support for caching with updating:
1) define in the manifest;
2) register for the FileUpdateRequested event;
3) process file update requests;
4) requires support from a remote server.
- Play To - implementation of playing the content of your application on an attached DLNA-compatible device;
An example application that implements a Play To contract
- Search - the ability to integrate with the standard search interface;
How to implement a search contract:
1) add the Search Contract element to the project (Add Item);
2) implement a search results page.
An example application that implements the Windows 8 search contract
. The "search" contract in detail
- Settings - the ability to provide user access to context-sensitive settings in a standard system metro view;
How to implement the Settings contract:
1) define in the manifest;
2) subscribe to the CommandRequested event of the SettingsPaneView object;
3) register your teams;
3) implement the handler (s) of the commands.
Sample application using integration settings
- Share is an easy way to provide or receive the content of your application to another application or service.
You can send / receive: text, URI, Bitmap, HTML, RTF and StorageItems
How to make Share Target:
1) add the "Share Target Contract" element to the project (Add Item);
2) add a declaration to the manifest;
3) implement the UI of receiving the
Application, an example of the implementation of the target application for Share
How to make the Share Source:
1) register yourself by calling DataTransferManager;
2) call ShowShareUI;
3) prepare the data for transmission.
Application, an example of the implementation of data sources for Share .
Let's move on to the extensions.
Extensions:
- Account Picture Provider - your application will be indicated in the list that provides the picture in the control panel
How to implement Account Picture Provider:
1) add an entry to the manifest;
2) in the OnActivated handler, work out activation according to the protocol with the ms-accountpictureprovider scheme ;
3) display the selection interface;
4) set the selected picture through UserInformation.SetAccountPicturesAsync.
An example of working with user account data, including his avatar
- AutoPlay - your application will be indicated in the list of applications for automatic playback when devices are connected to a computer
How to implement AutoPlay
1) add AutoPlay Content and / or AutoPlay Device to the manifest;
2) implement OnFileActivated processing.
An example of working with Removable Storage with the implementation of AutoPlay support
- Background Tasks - used by the application to run part of the application code when it is not executed
How to implement Background Tasks
1) add a definition to the manifest;
2) to implement, depending on the type of task.
The theme of background tasks is more complex than most of the rest, I plan to consider it in detail in the following articles.
An example with the basics of working with background tasks
An example of a background task that starts when SMS
arrives A background task that performs network availability A
background task that processes Raw alerts
- Camera Settings - the application can provide a special interface for configuring the camera and effects when photographing and shooting video
How to implement the Camera Settings contract:
1) add a definition to the manifest;
2) in the OnActivated application handler, work out activation by type ActivationKind.CameraSettings;
3) implement the necessary settings.
An example application for the camera and implementing the Camera Settings extension A
detailed guide for developing applications that work with the camera
- Contact Picker - the application will be shown in the list of applications that are displayed when choosing contacts
How to implement Contact Picker:
1) add a definition to the manifest;
2) in the OnActivated handler, work out the ActivationKind.ContactPicker activation type;
3) use ContactPickerUI to display a list of contacts.
Example application implementing the Contact Picker extension
- File Activation - the ability to register an application as a file handler of a certain type with a specific extension.
How to implement the File Activation extension:
1) add a definition to the manifest;
2) handle the OnFileActivated event.
An example application that implements the File and Protocol Activation extensions
- Game Explorer - to register a program in the system as a game, the developer needs to “support” this extension and create a Game Definition File. The process is described in more detail under the link Creating a GDF file
- Print Task Settings - the program can provide advanced options for setting up a print task.
How to implement the Print Task Settings extension:
1) add a definition to the manifest;
2) handle the OnActivated event with the type ActivationKind.PrintTaskSettings.
Sample application with implemented extension Print Task Settings
Detailed guide for developing applications that work with the printer
- Protocol Activation - the ability to register a protocol and / or handler to it.
How to implement the Protocol Activation extension:
1) add a definition to the manifest;
2) handle the OnActivated event for the type ActivationKind.Protocol.
An example application that implements the File and Protocol Activation extensions
- SSL / Certificate - This extension allows you to install digital certificates with your application. To do this, add the appropriate settings and certificate to the manifest.
If you want to try to implement some kind of contract or extension right now, then to start developing applications for Windows 8 you need to install free development tools on Windows 8 .