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.

setAccountPicturesAsync (for providing small and large images as well as a video from<br />

StorageFile objects), and setAccountPictureFromStreamAsync and<br />

setAccount-PicturesFromStreamAsync (which do the same given IRandomAccessStream objects<br />

instead). In each case the async result is a SetAccountPictureResult value: success, failure,<br />

changeDisabled (accountPictureChangeEnabled is false), large-OrDynamicError (the picture is<br />

too large), fileSizeError (file is too large), or video-FrameSizeError (video frame size is too<br />

large),<br />

• The accountpicturechanged event signals when the user picture(s) have been altered.<br />

Remember that because this event originates within WinRT you should call<br />

removeEvent-Listener if you aren’t listening for this event for the lifetime of the app.<br />

These features are demonstrated in the Account picture name sample. Scenario 1 retrieves the<br />

display name, Scenario 2 retrieves the first and last name (if available), Scenario 3 retrieves the account<br />

pictures and video, and Scenario 4 changes the account pictures and video and listens for picture<br />

changes.<br />

Tip To obtain the profile picture from Live Connect, the exact API call is as follows:<br />

https://apis.live.net/v5.0/me/picture?access_token=.<br />

One other bit that this sample demonstrates is the Account Picture Provider declaration in its<br />

manifest, which causes the app to appear within PC Settings > Personalize under Create an Account<br />

Picture:<br />

In this case the sample doesn’t actually provide a picture directly but activates into Scenario 4. A real<br />

app, like the Camera app that’s also in PC Settings by default, will automatically set the account picture<br />

when one is acquired through its UI. How does it know to do this? The answer lies in a special URI<br />

scheme through which the app is activated. That is, when you declare the Account Picture Provider<br />

declaration in the manifest, the app will be activated with the activation kind of protocol (see Chapter<br />

12, “Contracts”), where the URI scheme specifically starts with ms-accountpictureprovider. You can see<br />

how this is handled in the sample’s js/default.js file:<br />

if (eventObject.detail.kind === Windows.ApplicationModel.Activation.ActivationKind.protocol) {<br />

// Check if the protocol matches the "ms-accountpictureprovider" scheme<br />

if (eventObject.detail.uri.schemeName === "ms-accountpictureprovider") {<br />

669

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

Saved successfully!

Ooh no, something went wrong!