Upload
richard-owen
View
219
Download
0
Tags:
Embed Size (px)
Citation preview
www.buildwindows.com
APP-398T
How to declare your app’s capabilities
Jeff JohnsonDirector of DevelopmentWindows User ExperienceMicrosoft Corporation
www.buildwindows.com
Agenda
• Explore the capability model for Metro style apps• Best practices for accessing the file system and
devices• New features for working with capabilities
You’ll leave with examples of how to• Identify and add any required capabilities• Incorporate programmatic file access in your app
Capabilities provide access to system resources and connected devices, and are declared in the
package manifest.
www.buildwindows.com
Capabilities enable…
• Easy programmatic access to the file system, file type associations, and new system UI controls for opening files
• Simple integration with the file system and connected devices like webcams and location sensors
• New declarative access model for PC resources that shows users app capabilities prior to purchase
Capabilities in the Store
www.buildwindows.com
• Users are notified about which capabilities an app declares as part of their app Store acquisition • Ensure that requested capabilities match customer
expectations
• Users can also easily enable or disable access to sensitive devices via the Settings Charm for each app
• File type associations are also declarative, and users can select their preferred applications for each file type
Keeping the user in control
Suspect capabilities
This app could use your:LocationDocuments LibraryWebcamMicrophone
www.buildwindows.com
Invocation & Contracts
Windows Runtime environment
AppContainer – Signed + Validated
process.exe
WinRT
APIs
Core OS
Direct API calls
Filtered to declared capabilities in the package manifest
www.buildwindows.com
Metro style app packages
• A package contains each Metro style app
• Delivered by a single trusted store
• Easy for users to install and uninstall
• Explicitly declares the app interface points used• Capabilities• Devices• File type associations• App contracts
www.buildwindows.com
File capabilities
• musicLibrary• picturesLibrary• videoLibrary• documentsLibrary• removableStorage
www.buildwindows.com
Device capabilities
• webcam• microphone• location• sms• proximity• extensible to new device classes…
www.buildwindows.com
Network & identity capabilities
• Network capabilities• internetClient• internetClientServer• privateNetworkClientServer
• Identity capabilities• defaultWindowsCredentials• sharedUserCertificates
Manifest Designer
Example: capabilities XML
<Capabilities> <Capability Name="picturesLibrary" /> <Capability Name="internetClient" /></Capabilities>
Packages without capabilities still have access to private working
folders, and simple sensors such as accelerometers.
www.buildwindows.com
Accessing the file system via the file picker
demo
Opening multiple items
// JavaScriptvar picker = new Windows.Storage.Pickers.FileOpenPicker();
picker.fileTypeFilter.replaceAll(["*"]);
picker.pickMultipleFilesAsync().then(function (files) { if (files.size > 0) { // Manipulate array of picked file(s) } else { // No files were returned. }});
// C#FileOpenPicker picker = new Windows.Storage.Pickers.FileOpenPicker();
picker.fileTypeFilter.replaceAll(["*"]);
IReadOnlyList<StorageFile> files = await openPicker.PickMultipleFilesAsync();if (files.Count > 0) { // Manipulate array of picked file(s)} else { // No files were returned. }
Saving a file (JavaScript)// JavaScriptvar savePicker = new Windows.Storage.Pickers.FileSavePicker();savePicker.defaultFileExtension = ".docx";savePicker.suggestedFileName = "New Document";savePicker.fileTypeChoices.insert("Microsoft Word Document", [".docx", ".doc"]);savePicker.fileTypeChoices.insert("Plain Text", [".txt"]);
savePicker.pickSaveFileAsync().then( function (file) { if (file) { // Application now has read/write access to the saved file } else { // A file was not returned (cancelled, access denied, etc.) } });
www.buildwindows.com
Picker properties
• Presentation mode• thumbnail, list
• Default location• Individual user libraries or computer
• Custom button labels • Open, Save, Import, Upload, etc.
• Picker Identifier• Allows multiple picker contexts within an app
Programmatic access to files and folders
www.buildwindows.com
Programmatic access to the Pictures Library
demo
www.buildwindows.com
Documents Library & removable storage
• Access to the documents library and removable storage is filtered to file type associations in your package manifest.
www.buildwindows.com
Accessing the Documents Library
demo
www.buildwindows.com
File type associations
• Registration via manifest• File type associations are statically declared in the
manifest.• Users receive a toast if your app can open a previously
registered file type. • Launch events are handled as part of application
activation.// Receive activation.function onActivatedHandler(eventArgs) { if (eventArgs.kind == Windows.ApplicationModel.Activation.ActivationKind.file) { // ...
Device capabilities
www.buildwindows.com
Using devices
• Simple integration with native and specialized devices
• Declarative access model for common device classes • Webcam and microphone• Location • Proximity• SMS• And others…
• User consent model for sensitive device classes
www.buildwindows.com
How to handle absence of a device?
• Developers should handle the absence of a device because• The device may not always be present or operational• The user can disable access in the app
• Defer access to devices until absolutely needed
• Plan for secondary experiences when a device is not available
www.buildwindows.com
Consent prompt and granting/disabling access (location)
demo
Recap
www.buildwindows.com
Recap
• Declare the capabilities you need
• Request only the capabilities you need
• Defer using devices until they are actually needed
• Build great experiences that respect customer decisions
www.buildwindows.com
Related sessions
• [PLAT-282T] File type associations and AutoPlay• [HW-745T] Reimagining the experience for connecting with
devices• [HW-747T] Building Metro style apps that connect to
specialized devices • [PLAT-785T] Creating connected apps that just work on
today's networks • [PLAT-894T] Seamlessly interacting with web and local data
www.buildwindows.com
Further reading and documentation
• File SDK samples• File access• File picker• Folder enumeration
• Device SDK samples• Geolocation• Media capture
www.buildwindows.com
• Feedback and questions http://forums.dev.windows.com
• Session feedbackhttp://bldw.in/SessionFeedback
thank you
© 2011 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to
be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.