New Windows Phone Device Status APIs#

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

private string m_DeviceManufacturer;
       
public string DeviceManufacturer
{
    get
    {
        if (m_DeviceManufacturer == null)
        {
            object val;
            if (DeviceExtendedProperties.TryGetValue("DeviceManufacturer", out val))
                m_DeviceManufacturer = val.ToString();
        }
        return m_DeviceManufacturer;
    }
}

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


Tuesday, June 28, 2011 1:48:41 AM (Eastern Daylight Time, UTC-04:00) #    Comments [0]  |  Trackback Tracked by:
"Summary of Windows Phone Mango Posts" (Mark Arteaga) [Trackback]
"Long Weekend Plans? One Word – Mango" (Canadian Mobile Developers' Blog) [Trackback]
"Long Weekend Plans? One Word – Mango" (Dev Pulse) [Trackback]

 

All content © 2012, Mark Arteaga
Related Sites
Archives
Sitemap
Disclaimer

Powered by: newtelligence dasBlog 1.9.7174.0

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

Send mail to the author(s) E-mail

Theme design by Jelle Druyts