23.01.2018 Views

MICROSOFT_PRESS_EBOOK_PROGRAMMING_WINDOWS_8_APPS_WITH_HTML_CSS_AND_JAVASCRIPT_PDF

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

var dataPackageTitle = document.getElementById("titleInputBox").value;<br />

if ( /* Check if there is appropriate data to share */ ) {<br />

request.data.properties.title = dataPackageTitle;<br />

// The description is optional.<br />

var dataPackageDescription = document.getElementById("descriptionInputBox").value;<br />

request.data.properties.description = dataPackageDescription;<br />

}<br />

// Call request.data.setText, setUri, setBitmap, setData, etc.<br />

} else {<br />

request.failWithDisplayText(/* Error message */ );<br />

}<br />

As we see here, the request.data.properties object (of type DataPackagePropertySet) is where<br />

you set things like a title and description for the data package. Other properties are as follows:<br />

• applicationListingUri The URI of your app’s page in the Windows Store, which should be set<br />

to the return value of Windows.ApplicationModel.Store.CurrentApp.linkUri 57 )<br />

• applicationName A string, which helps share targets gather the same kind of information that<br />

the source can obtain from the targetApplicationChosen event<br />

• fileTypes A string vector, where strings should come from the StandardDataFormats<br />

enumeration but can also be custom formats<br />

• size The number of items when the data in the package is a collection, e.g., files<br />

• thumbnail A stream containing a thumbnail image; obtaining this image is typically why you’d<br />

use the DataRequest.getDeferral method).<br />

Beyond this the data.properties object also supports custom properties through its insert, remove,<br />

and other methods. This makes is possible for the source app to pass custom properties along with<br />

custom formats, making all of this extensible if new data formats are widely adopted in the future.<br />

Within this code structure above, the primary job of the source app is to populate the data package<br />

by calling the package’s various set* methods. For standard formats, which are again those described in<br />

the StandardDataFormats enumeration, there are discrete methods: setText, setUri, setHtmlFormat,<br />

setRtf (rich text format, a comparably ancient precursor to <strong>HTML</strong>), setBitmap, and setStorageItems (for<br />

files and folders). All of these except for setRtf are represented in the source app sample as follows.<br />

57 This URI along the applicationName would allow a target to indicate where the data originally came from, especially for<br />

scenarios where the data goes to a social network, in an email message, or elsewhere off the device with the source app.<br />

This way, recipients can be invited to acquire the source app themselves, so source apps will probably want to include it.<br />

You always want to use the Windows.ApplicationModel.Store.CurrentApp.linkUri property to populate this field<br />

because you won’t know your URI until your completed app is uploaded to the Store the first time.<br />

497

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!