Getting Device Information in WindowsPhone 7

Assuming you need to get some information from your Windows Phone 7 Device, I will be showing you how to do it easily.

As I am using an emulator, we won't get healthy results about Device ID. So you will need to test it in a real device.

So here it goes.

We will be getting the following information in our sample:

  • Manufacturer
  • Device Name
  • Device ID
  • Firmware Version
  • Hardware Version
  • Total Memory
  • Application Current Memory Usage
  • Application Peak Memory Usage

In this sample we will be getting this information in every 3 seconds using DispatcherTimer and show the results in 8 textblock controls.

I have designed this for our sample:


Here its XAML:

    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"

    <Grid x:Name="LayoutRoot" Background="Transparent">
        <StackPanel x:Name="TitlePanel" Margin="12,17,0,751"></StackPanel>
        <Grid x:Name="ContentPanel" Margin="12,161,12,0">
            <TextBlock Height="30" HorizontalAlignment="Left" Margin="24,40,0,0" Name="textBlock1" Text="Manufacturer: " VerticalAlignment="Top" />
            <TextBlock Height="30" HorizontalAlignment="Left" Margin="221,40,0,0" Name="textBlock2" Text="" VerticalAlignment="Top" Width="229" />
            <TextBlock Height="30" HorizontalAlignment="Left" Margin="24,76,0,0" Name="textBlock3" Text="Device Name: " VerticalAlignment="Top" />
            <TextBlock Height="30" HorizontalAlignment="Left" Margin="221,76,0,0" Name="textBlock4" Text="" VerticalAlignment="Top" Width="229" />
            <TextBlock Height="30" HorizontalAlignment="Left" Margin="24,112,0,0" Name="textBlock5" Text="Device ID: " VerticalAlignment="Top" />
            <TextBlock Height="30" HorizontalAlignment="Left" Margin="221,112,0,0" Name="textBlock6" Text="" VerticalAlignment="Top" Width="229" FontSize="15" />
            <TextBlock Height="30" HorizontalAlignment="Left" Margin="24,148,0,0" Name="textBlock7" Text="Firmware Version: " VerticalAlignment="Top" />
            <TextBlock Height="30" HorizontalAlignment="Left" Margin="221,148,0,0" Name="textBlock8" Text="" VerticalAlignment="Top" Width="229" />
            <TextBlock Height="30" HorizontalAlignment="Left" Margin="24,184,0,0" Name="textBlock9" Text="Hardware Version: " VerticalAlignment="Top" />
            <TextBlock Height="30" HorizontalAlignment="Left" Margin="221,184,0,0" Name="textBlock10" Text="" VerticalAlignment="Top" Width="229" />
            <TextBlock Height="30" HorizontalAlignment="Left" Margin="24,220,0,0" Name="textBlock11" Text="Total Memory: " VerticalAlignment="Top" />
            <TextBlock Height="30" HorizontalAlignment="Left" Margin="221,220,0,0" Name="textBlock12" Text="" VerticalAlignment="Top" Width="229" />
            <TextBlock Height="30" HorizontalAlignment="Left" Margin="24,256,0,0" Name="textBlock13" Text="Current Memory Use: " VerticalAlignment="Top" />
            <TextBlock Height="30" HorizontalAlignment="Left" Margin="221,256,0,0" Name="textBlock14" Text="" VerticalAlignment="Top" Width="229" />
            <TextBlock Height="30" HorizontalAlignment="Left" Margin="24,292,0,0" Name="textBlock15" Text="Peak Memory Use: " VerticalAlignment="Top" />
            <TextBlock Height="30" HorizontalAlignment="Left" Margin="221,292,0,0" Name="textBlock16" Text="" VerticalAlignment="Top" Width="229" />
        <TextBlock Height="60" HorizontalAlignment="Left" Margin="12,17,0,0" Name="textBlock17" Text="Device Information Center" VerticalAlignment="Top" FontSize="32" Width="402" />

  • Manufacturer = textBlock2

  • Device Name = textBlock4

  • Device ID = textBlock6

  • Firmware Version = textBlock8

  • Hardware Version = textBlock10

  • Total Memory = textBlock12

  • Application Current Memory Usage = textBlock14

  • Application Peak Memory Usage = textBlock16

So let's write some code for getting the info.

First of all we're creating a DispatcherTimer object

DispatcherTimer timer;

You'll need to add System.Windows.Threading namespace to use DispatcherTimer.

Add a string variable to get Device ID in string format:

public static string val;

Write a function that returns Device ID in byte. But we're converting the result to a string value.

public static byte[] GetDeviceUniqueID()
   byte[] result = null;
   object uniqueId;
   if (DeviceExtendedProperties.TryGetValue("DeviceUniqueId", out uniqueId))
       result = (byte[])uniqueId;
   return result;

I found and changed a bit of this code in Nick Harris's Blog:

We can get the Device ID in a byte array. But we could iterate (using a for-loop) through the array and get some values. But it would be unnecessary. So we are converting our byte array into a string to read it more clearly and assign it to a static string variable named "val"

Next we are adding the following code to our Page's constructor to start Timer and get Unique Device ID:

timer = new DispatcherTimer();
timer.Interval = new TimeSpan(0, 0, 3);
timer.Tick += new EventHandler(timer_Tick);

And add our timer_Tick function:

void timer_Tick(object sender, EventArgs e)

    textBlock2.Text = DeviceExtendedProperties.GetValue("DeviceManufacturer").ToString();
    textBlock4.Text = DeviceExtendedProperties.GetValue("DeviceName").ToString();
    textBlock6.Text = val;
    textBlock8.Text = DeviceExtendedProperties.GetValue("DeviceFirmwareVersion").ToString();
    textBlock10.Text = DeviceExtendedProperties.GetValue("DeviceHardwareVersion").ToString();
    textBlock12.Text = DeviceExtendedProperties.GetValue("DeviceTotalMemory").ToString();
    textBlock14.Text = DeviceExtendedProperties.GetValue("ApplicationCurrentMemoryUsage").ToString();
    textBlock16.Text = DeviceExtendedProperties.GetValue("ApplicationPeakMemoryUsage").ToString();              
   catch (Exception ex)



We can use DeviceExtendedProperties to get information about WP7 Device. The parameters are as described here:

After we run the application.

We will be getting our information about WP7 Device:


As I have said before since we're using an emulator we won't be getting an acceptable Device ID. So the result is as you see. But if you try it with a real WP7 device, I'm sure you'll get real results.

Hope this article helps you.

Araf Global is a software consultancy company founded in 2016 focusing on cutting edge technologies.