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
<span style="color: blue;">private string </span>m_DeviceManufacturer;
<span style="color: blue;">public string </span>DeviceManufacturer
<span style="color: blue;">get
<span style="color: blue;">if </span>(m_DeviceManufacturer == <span style="color: blue;">null</span>)
<span style="color: blue;">object </span>val;
<span style="color: blue;">if </span>(DeviceExtendedProperties.TryGetValue(<span style="color: #a31515;">"DeviceManufacturer"</span>, <span style="color: blue;">out </span>val))
m_DeviceManufacturer = val.ToString();
<span style="color: blue;">return </span>m_DeviceManufacturer;
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.
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
- KeyboardDeployedChanged – Will notify you when the physical keyboard is exposed or hidden by the user
- PowerSourceChanged – Will notify you when the device has or lost power
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 )
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.
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