New Windows Phone Device Status APIs

June 28, 2011 — 1 Comment

Windows Phone Mango introduces some new APIs to help get device status.  In pre-Mango APIs, we would have to use the Microsoft.Phone.Info.DeviceExtendedProperties to get different status such as device total memory, device manufacturer and the code was a bit messy.

One of the key ones is DeviceTotalMemory which allows you to see how much memory your application is currently consuming. This is especially useful since one of the Marketplace Certification Requirements says that you cannot consume more the 90MB of memory on devices with 256MB of memory or less.

For example, to get the DeviceManufacturer details you would use something like the following

In our case, we wrote a wrapper to all the Device Extended Properties calling it RedBit.WindowsPhone.DeviceInfo so it’s more easily accessible via an object modelimage

New to Mango

With Windows Phone Mango the above is no longer required since there is a new Microsoft Microsoft.Phone.Info.DeviceStatus Class which wraps a lot of these properties but also adds a few interesting ones.

image

You will notice comparing the two, everything looks essentially the same, so the Windows Phone API team decided to make developers lives easier and create this class so you don’t have to use DeviceExtendedProperties anymore.  Of course, in some instances you still may have to, for example when wanting to get the DeviceUniqueId.

So what’s of Interest?
A few properties that jump out at me are

  • IsKeyboardDeployed – Tells you if the user has has exposed the physical hardware keyboard to start typing instead of using the onscreen software keyboard
  • IsKeyboardPresent – Tells you if the device even has a physical hardware keyboard
  • PowerSource – Tells you if the device is on battery power or is plugged in

And some events that jump out are

One possible use for the IsKeyboardPresent property is for games.  If the keyboard is available, you can use physical keys to move players around instead of taking up screen real estate with your fingers. (Thanks to Barranger Ridler for that idea Smile)

For PowerSource and PowerSourceChanged, you can use this to adjust something in your app to minimize battery usage.  For example, if you are not plugged in, request for updates from a backend service every 30mins, but if the device is plugged in, request for updates every 1min.  This will significantly help conserve battery which gives a better end use experience.

Moving Onward

My hope is this is the first of many new APIs in the DeviceStatus class and we get back in line with the State and Notification Broker we had in Windows Mobile were you can do things such as intercept incoming text messages and phone calls.  For Mango, I think this is the right level of exposure that is required for now. But of course as developers we’ll always want more Smile

One response to New Windows Phone Device Status APIs

  1. This has made my day. I wish all potsgins were this good.

Leave a Reply