Using connected devices in Metro style apps 12/5/2018 7:48 PM PLAT-278T Using connected devices in Metro style apps Jack Tao Program Manager Lisa Ong Software Developer Microsoft Corporation © 2010 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.
Agenda Creating possibilities for your app with devices Finding a device to use in your Metro style app Using a device in your Metro style app You’ll leave with examples of how to Make your app more exciting by integrating with devices
Your Metro style app can seamlessly integrate device access.
Using devices from your Metro style app Ecosystem of devices carrying a lot of data and content Apps create more possibilities with access to device content Windows APIs enable you to build apps that leverage devices
Creating possibilities for your app with devices
It’s easy for your Metro style app to use a variety of devices.
Using SMS and Location in a Metro style app demo Where’s my lost tablet? Using SMS and Location in a Metro style app
How I found my lost tablet from: 425-mylaptop to: 425-mytablet body: Where is my tablet? my laptop @ //build/ from: 425-mytablet to: 425-mylaptop body: 47.XXXXX, -122.YYYYY my lost tablet @ my office! location ???
Using SMS & Location Through Windows, your app can send & receive SMS using mobile broadband Through Windows, your app can easily integrate Location
Variety of devices
Devices carry a ton of information Music Photos Videos Documents Contacts, calendar, tasks, notes Text messages Location and routes Workout stats Health data
Many common scenarios include devices Uploading vacation photos, movies from camera to SkyDrive Importing contacts from phone Backing up data to external storage Getting trip history from personal navigation device Tracking daily workout from a fitness device Sending and receiving SMS messages with mobile broadband
Your app can easily use device content with cloud services.
Uploading photos from a camera to SkyDrive 12/5/2018 7:48 PM demo Photo uploader Uploading photos from a camera to SkyDrive © 2010 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.
Portable storage & web services Through Windows, your app can easily access content stored on devices Through Windows, your app can share content from devices to an online service
You can create mash-up apps that use devices in new ways.
Visualizing maps from an off-the-shelf GPS 12/5/2018 7:48 PM demo Rally trip Visualizing maps from an off-the-shelf GPS © 2010 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.
Portable storage & mash-ups Your app can combine data from devices & web services to create a mash-up Mash-up apps provide rich and exciting ways to use content from devices
Using devices in your app Ecosystem of devices more More possibilities + Your Metro style app
Finding a device to use in your Metro style app
Ways your app can find devices to use Multiple/externally-connected Use Windows.Devices.Enumeration Perform queries to list devices Get device icon, name, etc. Get connect/disconnect events Single/built-in Get the default device
Find devices by query & enumeration.
Finding all portable storage devices var query = Windows.Devices.Enumeration.DeviceClass.portableStorageDevice; Windows.Devices.Enumeration.DeviceInformation.findAllAsync(query). then(function (storageDevices) { var name = storageDevices[0].name; storageDevices[0].getThumbnailAsync(function (deviceIcon) { var imageTag = document.createElement('img'); imageTag.src = URL.createObjectURL(deviceIcon, …); // PNG format }); var storageDevice = Windows.Devices.Portable.StorageDevice.fromId(storageDevices[0].id);
Find a built-in device with one line of code. Start using it right away.
Use the .getDefault( ) pattern var smsDevice = Windows.Devices.Sms.SmsDevice.getDefault(); // Start sending & receiving SMS … var inclinometer = Windows.Devices.Sensors.Inclinometer.getDefault(); // Start writing your racing game … var proximity = Windows.Networking.Proximity.ProximityDevice.getDefault(); // Start discovering nearby PCs …
Using a device in your Metro style app
Ways your app can use devices Use files stored on the device File APIs for searching and acting on files Send & receive SMS using mobile broadband Access contacts on a phone Portable devices APIs for unique functionality
Search files on a device and use them directly.
Upload external camera photos to SkyDrive var options = new Windows.Storage.Search.QueryOptions(…, [".jpg", ".png"]); var query = storageDevice.createFileQueryWithOptions(options); query.getFilesAsync(). then(function (pictureFiles) { picturesFiles.forEach(function (pictureFile) { WL.upload({ path: "me/skydrive", file: pictureFile, … }); });
Send & receive SMS quickly and easily.
Use SMS to locate a lost PC // Send an SMS to locate a second, lost PC var msg = new Windows.Devices.Sms.SmsTextMessage(); msg.to = "14250000000"; msg.body = "Where is my tablet?"; smsDevice.sendMessageAsync(msg).then(…); ------------------------------------------------------------ // Elsewhere …, on the lost PC smsDevice.onsmsmessagereceived = function (event) { var messageBody = event.textMessage.body; // Parse message body and reply with current location };
Access a phone’s contacts and unique functionality.
Get contacts from a phone // Contacts stored as data in the phone's Contacts Service Windows.Devices.Enumeration.DeviceInformation.findAllAsync(contactsServiceQuery). then(function (devices) { var device = portableDeviceFactory.getDeviceFromId(devices[0].id); var contactsService = device.services[0]; // Get all contact data stored in the vcard2 format contactsService.onGetChildrenByFormatComplete = function (contacts) { … }; contactsService.getChildrenByFormat("vcard2"); });
Be sure to declare the necessary capabilities in your app manifest.
Recap
Your Metro style app can seamlessly integrate device access.
Key takeaways Ecosystem of devices carrying a lot of data and content Apps create more possibilities with access to device content Windows APIs enable you to build apps that use devices
+ app devices more Ecosystem of devices More possibilities Your Metro style app
Related sessions [APP-398T] How to declare your app’s capabilities [APP-405T] Share: your app powers the Windows 8 share experience [PLAT-282T] File type associations and AutoPlay [PLAT-781T] Using location & sensors in your app [PLAT-891T] Using files: accessing, searching, and acting on files [HW-747T] Building Metro style apps that connect to specialized devices
Further reading and documentation Metro style device experience Windows.Devices.Enumeration namespace Windows.Devices.Portable namespace Windows.Devices.Sms namespace
thank you Feedback and questions http://forums.dev.windows.com Session feedback http://bldw.in/SessionFeedback
12/5/2018 7:48 PM © 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. © 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.