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

  • Live Event Date: December 11, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Market pressures to move more quickly and develop innovative applications are forcing organizations to rethink how they develop and release applications. The combination of public clouds and physical back-end infrastructures are a means to get applications out faster. However, these hybrid solutions complicate DevOps adoption, with application delivery pipelines that span across complex hybrid cloud and non-cloud environments. Check out this …

  • CentreCorp is a fully integrated and diversified property management and real estate service company, specializing in the "shopping center" segment, and is one of the premier retail service providers in North America. Company executives travel a great deal, carrying a number of traveling laptops with critical current business data, and no easy way to back up to the network outside the office. Read this case study to learn how CentreCorp implemented a suite of business continuity services that included …

Most Popular Programming Stories

More for Developers

RSS Feeds