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.

Toast Notifications<br />

So far in this chapter we’ve exhausted the subject of tiles and tile updates, which is actually a great<br />

prelude to our next topic, toast notifications. This is because the process of creating and issuing toasts is<br />

quite similar to that for tiles and is simplified by the fact that there are no periodic updates for toasts:<br />

they either come from the running app, from background tasks, or through push notifications, as we’ll<br />

see in “Push Notifications and the Windows Push Notification Service” below. Fortunately, the topic of<br />

toasts is considerably shorter than that of tiles. Here are the salient aspects of toasts:<br />

• Toasts always use the app’s Background Color and Foreground Text settings in the manifest for<br />

branding, along with the small logo. There are no means to override this; the branding attribute<br />

in the XML is ignored for toasts.<br />

• An app must set the Toast Capable setting in its manifest for any toasts to appear on its behalf.<br />

This is found in the Application UI > Notifications area:<br />

• As shown long ago in Figure 13-8, the user can disable toasts for a particular app or disable<br />

them globally (which I find helpful when recording a screencast!). System administrators can also<br />

disable toasts by policy. To check this status programmatically, look at the Toast-<br />

Notifier.setting property, a value from the NotificationSetting enumeration that will be<br />

enabled, disabledForApplication, disabledForUser, or disabledByGroupPolicy.<br />

• When enabled, toasts always appear in the upper right corner of the screen (left-to-right<br />

languages) or the upper left corner (right-to-left languages). This is not configurable.<br />

• Toasts are managed through instances of the Windows.UI.Notifications.ToastNotification<br />

or Windows.UI.Notifications.ScheduledToastNotification classes. The first supports an<br />

expirationTime property; the scheduled toast supports deliveryTime, snoozeInterval, and<br />

maximumSnoozeCount properties.<br />

• As with tiles, the content of toasts are created with an XML payload from one of four text-only<br />

and four image-plus-text templates, as shown on the Toast template catalog. Toast templates<br />

are acquired from the ToastNotificationManager object’s getTemplateContent method, can be<br />

created from strings, or can be created through the Notifications Extensions Library. Various<br />

options can be set in the XML:<br />

599

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

Saved successfully!

Ooh no, something went wrong!