5 out of 6 rated this helpful - Rate this topic

How to: Use the DeviceStatus Class for Windows Phone

Windows Phone

March 22, 2012

You can use the DeviceStatus API to determine status information about the device, such as the total memory of the device, the hardware version of the device, and whether a physical keyboard has been deployed. In addition, you can register for several events that notify your application when certain properties have changed.

The guidance and code examples in this topic are based on an end-to-end code sample called Device Status Sample, which can be downloaded at Code Samples for Windows Phone.

The following code example shows how to access the properties of the DeviceStatus class and output the values into the Text property of TextBlock controls.

deviceManufacturerTextBlock.Text = DeviceStatus.DeviceManufacturer;
deviceNameTextBlock.Text = DeviceStatus.DeviceName;
deviceFirmwareVersionTextBlock.Text = DeviceStatus.DeviceFirmwareVersion;
deviceHardwareVersionTextBlock.Text = DeviceStatus.DeviceHardwareVersion;
deviceTotalMemoryTextBlock.Text = DeviceStatus.DeviceTotalMemory.ToString();
appCurrentMemoryUsageTextBlock.Text = DeviceStatus.ApplicationCurrentMemoryUsage.ToString();
appMemoryUsageLimitTextBlock.Text = DeviceStatus.ApplicationMemoryUsageLimit.ToString();
appPeakMemoryUsageTextBlock.Text = DeviceStatus.ApplicationPeakMemoryUsage.ToString();
isKeyboardPresentTextBlock.Text = DeviceStatus.IsKeyboardPresent.ToString();
isKeyboardDeployedTextBlock.Text = DeviceStatus.IsKeyboardDeployed.ToString();
powerSourceTextBlock.Text = DeviceStatus.PowerSource.ToString();

First, set up the event handler, as shown in the following code example.

DeviceStatus.KeyboardDeployedChanged += new EventHandler(DeviceStatus_KeyboardDeployedChanged);

Next, invoke a Dispatcher to update the Text property of a TextBlock control, as shown in the following code example.

void DeviceStatus_KeyboardDeployedChanged(object sender, EventArgs e)
{
    // The KeyboardDeployedChanged event is not raised on the UI thread, 
    // so the Dispatcher must be invoked to update the Text property.
    this.Dispatcher.BeginInvoke(() => 
        {
            isKeyboardDeployedTextBlock.Text = DeviceStatus.IsKeyboardDeployed.ToString();
        }
    );
}

First, set up the event handler, as shown in the following code example.

DeviceStatus.PowerSourceChanged += new EventHandler(DeviceStatus_PowerSourceChanged);


Next, invoke a Dispatcher to update the Text property of a TextBlock control, as shown in the following code example.

void DeviceStatus_PowerSourceChanged(object sender, EventArgs e)
{
    // The PowerSourceChanged event is not raised on the UI thread, 
    // so the Dispatcher must be invoked to update the Text property.
    this.Dispatcher.BeginInvoke(() => 
        {
            powerSourceTextBlock.Text = DeviceStatus.PowerSource.ToString();
        }
    );
}

Did you find this helpful?
(1500 characters remaining)