Sunday 22 February 2015

Chapter Nine : Sharing Contract

Another Contract in Windows is SharingContract
Let’s begin to learn happily with this handout :)

The Sharing Contract, the user gets to be in full control.  You make your content shareable, and they decide where and how it gets shared. 

Users can also share to another user’s device using Tap and send in the Devices charm.

An app can support the Share feature in two ways:
It can be a source app that provides content that the user wants to share.
the app can be a target app that the user selects as the destination for shared content.
An app can also be both a source app and a target app. If you want your app to share content as a source app, you need to decide what data formats your app can provide.
Example of how to share content, check out our Sharing content source app sample and Sharing content target app sample, or read through our
Sharing content
 Receiving shared
Take a look at the following diagram. It shows, at a high level, how sharing works.
If you are implementing a target app, there are a couple of things you should consider.


when the user selects your app, Windows will display it using the Share flyout. You can specify a specific HTML file that opens when the app is activated through the Share charm.
Our Sharing content target app sample shows how this works, or you can check out our QuickStart: Receiving shared content for more details.
Guidelines for sharing content
When people swipe from the side of the screen and tap the share charm, the share pane appears with a list of apps people can share their content with. This list includes any apps that are “share targets” for a particular data format.

If your app has content to share, your app is a share source. If your app can receive content from other apps, then it’s a share target. Of course, apps can be both at once!
//When people choose to share content, source apps provide the requested content in a shareable format, and display the metadata in the content preview. The chosen target app launches, reads the shared content, and displays whatever UI is appropriate.
When the target app reports that the sharing operation has completed, it can return a QuickLink to be displayed in the share window//
Choosing data formats for sharing
you're writing a source app, which helps users share content, or a target app, which receives that content, you should take time to consider what data formats and file types you want to support. Here, we'll describe the standard formats that the Windows.ApplicationModel.DataTransfer namespace supports.
Choosing data formats for a source app
If you're writing a source app, you should provide your data in as many formats as possible. Start by including the format that makes the most sense to represent your data. Next, include additional formats that also accurately represent the data.
Example scenario: The user wants to share a selection from the article in your app. In this case, the HTML format most accurately reflects the user’s intent. You should also include a text version of the user’s selection. The recommended way to achieve this is to use MSApp.createDataPackageFromSelection.
Use this table to maximize the number of appropriate data formats your app includes in its DataPackage:
Content your app shares
Recommended DataPackage format
Additional formats your DataPackage should include
Unformatted plain text
Text
None
Link
Uri
Text
HTML, if you're creating a link back to your app.
HTML, if an abstract of the linked content is available. Include a link back to the source in the HTML data.
Formatted content/HTML
HTML
Text, if the content contains only text.
Bitmap, if the content contains only an image.
File
StorageItems
None
Single Image
Bitmap
StorageItems, if the image is also accessible as a file.
Multiple files and images
StorageItems
None
Choosing data formats for a target app
Use this table to maximize the number of appropriate data formats your app supports:
Primary data type your app supports
Recommended primary DataPackage format
Additional recommendations
Unformatted plain text
Text
Uri
Links
Uri
None
Note  Uniform Resource Identifiers (URIs) are not limited to http:// or https://. Any valid URI, including activation protocols, can be passed to your app.
Formatted content/HTML
HTML
Text
Uri
Bitmap
RTF
File
StorageItems
None
Single Image
Bitmap
StorageItems with file name extensions specific to images (.jpg, .gif, and so on)
Multiple files and images
StorageItems
None
Specific file types (such as .docx)
StorageItems with specific file name extensions
None

To share content in a variety of formats, including:

  • Text
  • URIs
  • Files
  • Images
  • Sharing content target app sample
An app can receive content shared from another app. This sample uses classes from the Windows.ApplicationModel.DataTransferand Windows.ApplicationModel.DataTransfer.Sharenamespaces.
Some of the classes you might want to review in more detail are the ShareOperationclass, which you use to manage a share operation, and the DataPackageViewclass, which you use to get the content being shared.
Because each share scenario usually involves two apps—the source app that provides the content and a target app that receives the content—.
To receive shared content in a variety of formats, including:

  • Text
  • Uniform Resource Identifiers (URIs)
  • Files
  • Images
By:
Khushbu Wadhwani,
Senior Windows app developer,
References:MSDN,Microsoft developer forum



No comments:

Post a Comment