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

  • Instead of only managing projects organizations do need to manage value! "Doing the right things" and "doing things right" are the essential ingredients for successful software and systems delivery. Unfortunately, with distributed delivery spanning multiple disciplines, geographies and time zones, many organizations struggle with teams working in silos, broken lines of communication, lack of collaboration, inadequate traceability, and poor project visibility. This often results in organizations "doing the …

  • With JRebel, developers get to see their code changes immediately, fine-tune their code with incremental changes, debug, explore and deploy their code with ease (both locally and remotely), and ultimately spend more time coding instead of waiting for the dreaded application redeploy to finish. Every time a developer tests a code change it takes minutes to build and deploy the application. JRebel keeps the app server running at all times, so testing is instantaneous and interactive.

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds