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: December 18, 2014 The Internet of Things (IoT) incorporates physical devices into business processes using predictive analytics. While it relies heavily on existing Internet technologies, it differs by including physical devices, specialized protocols, physical analytics, and a unique partner network. To capture the real business value of IoT, the industry must move beyond customized projects to general patterns and platforms. Check out this webcast and join industry experts as …

  • Today's agile organizations pose operations teams with a tremendous challenge: to deploy new releases to production immediately after development and testing is completed. To ensure that applications are deployed successfully, an automatic and transparent process is required. We refer to this process as Zero Touch Deployment™. This white paper reviews two approaches to Zero Touch Deployment--a script-based solution and a release automation platform. The article discusses how each can solve the key …

Most Popular Programming Stories

More for Developers

RSS Feeds