Getting to Know More About Your Windows Phone

Introduction

There are cases when Windows Phone developers need to retrieve device information so that they can author their applications to draw the maximum possible juice from the device.  They can also use this data to see what hardware their customers use and optimize their application to provide a better experience for the most popular harware.

Device Information

Windows Phone platform has a rich set of APIs to support getting device information. These APIs reside in the DeviceStatus class in the Microsoft.Phone.Info namespace.

The DeviceStatus class has APIs to get information like the hardware version of the phone, total memory on the phone, etc.

Hands-on

Let us write an application that gets the device information and displays it to the user.

Create a new Windows Phone application called WPDeviceInfoDemo.

Create a new Windows Phone application
Create a new Windows Phone application

When prompted for the target OS version, select WP7.1 and click OK.

Select the Windows Phone Platform
Select the Windows Phone Platform

Next, add controls on the MainPage to display “Current memory”, “Total memory”, “Device Hardware version”, “Device Firmware Version”, and a checkbox to show if a “Physical Keyboard” is present. Add a button titled “Get Device Data,” which we will use to get the device information.

Next, open MainPage.xaml.cs and include the Microsoft.Phone.Info namespace.

using Microsoft.Phone.Info;

Next, add an event handler for the click event on the button. In this method, we will get the device information using the methods of the DeviceStatus class.

private void buttonGetDeviceData_Click(object sender, RoutedEventArgs e)
        {
            textBlockCurrentMemoryValue.Text = DeviceStatus.ApplicationCurrentMemoryUsage.ToString();
            textBlockTotalMemoryValue.Text = DeviceStatus.DeviceTotalMemory.ToString();
            textBoxDeviceFWVersion.Text = DeviceStatus.DeviceFirmwareVersion;
            textBoxDeviceHardwareVersion.Text = DeviceStatus.DeviceHardwareVersion;
            checkBoxPhysicalKeyboardPresent.IsChecked = DeviceStatus.IsKeyboardPresent;
        }

We are now ready to build and test our application. If you are having issues compiling the code, you can download copy of the source code below.

When you run the application, you will find that when you click the button, the device information is retrieved and shown on the screen.

Caveat: If you run the application in an emulator, the device hardware and device firmware will be reported as 0.0.0.0.

The device information is shown on the screen
The device information is shown on the screen

Other uses

You can also use the DeviceStatus calss to see the power source for the device, and also whenever a physical keyboard is deployed.

Summary

In this article, we learned how we can get device information.

About the author

Vipul Patel is a Program Manager currently working at Amazon Corporation. He has formerly worked at Microsoft in the Lync team and in the .NET team (in the Base Class libraries and the Debugging and Profiling team). He can be reached at vipul_d_patel@hotmail.com



Related Articles

Downloads

Comments

  • great piece of information

    Posted by khan on 09/18/2012 03:27am

    hi Vipul, thats a great piece of information you have shared with us over here. I am currently working on developing an application for Windows Phone. I need to find out memory usage by different programs loaded in the memory. do you know about any such function/class which could return me this thing. kindly let me know thanks and regards, Saad khan Mobile dev engineer. www.amcoitsystems.com E: saad.khan [at] amcoitsystems.com

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • On-demand Event Event Date: September 10, 2014 Modern mobile applications connect systems-of-engagement (mobile apps) with systems-of-record (traditional IT) to deliver new and innovative business value. But the lifecycle for development of mobile apps is also new and different. Emerging trends in mobile development call for faster delivery of incremental features, coupled with feedback from the users of the app "in the wild." This loop of continuous delivery and continuous feedback is how the best mobile …

  • On-demand Event Event Date: September 17, 2014 Another day, another end-of-support deadline. You've heard enough about the hazards of not migrating to Windows Server 2008 or 2012. What you may not know is that there's plenty in it for you and your business, like increased automation and performance, time-saving technical features, and a lower total cost of ownership. Check out this webcast and join Rich Holmes, Pomeroy's practice director of virtualization, as he discusses the future state of your servers, …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds