Compartir a través de


Device status for Windows Phone 8

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

You can use the DeviceStatus class to determine status info 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 app when certain properties have changed.

In Windows Phone OS 7.0, the DeviceExtendedProperties class was used to query device-specific properties. In all newer versions, the DeviceExtendedProperties class is deprecated, and the new DeviceStatus class should be used instead. However, where appropriate, you can still use the properties in DeviceExtendedProperties that are not deprecated.

Important Note:

See the Device Status Sample and How to use the DeviceStatus class for Windows Phone 8 for code examples of how to use this class.

This topic contains the following sections.

Common scenarios

  • General device info

    You can query DeviceStatus properties to receive info about the device, such as total memory, hardware version, and device manufacturer name.

  • Apps that run outside of the lock screen

    Certain types of apps, such as a simple alarm clock app that travelers use to display the date and time, benefit the user by running outside of the lock screen. In combination with asking the user for permission, you can use the PowerSource API and the PowerSourceChanged event to know when the phone has been plugged into an external source of power.

  • Keyboard availability

    Your app could choose to support a landscape or portrait mode depending on whether a hardware keyboard is available. You can use the IsKeyboardPresent property, the IsKeyboardDeployed property, and the KeyboardDeployedChanged event for these or other apps.

  • Monitoring memory usage

    As you develop your app, you can use the ApplicationCurrentMemoryUsage and ApplicationPeakMemoryUsage properties to monitor memory usage, and the DeviceTotalMemory and ApplicationMemoryUsageLimit properties to determine device and app memory limits. It is not necessary to check the memory usage of your app at extremely small intervals. It is sufficient to occasionally check peak memory usage. If you find that the peak memory usage value crosses the allowable threshold, as described in section 5.2 of Technical certification requirements for Windows Phone, you may choose to monitor memory usage more finely in order to help diagnose the problem.

    If your app is consuming a lot of memory, track the instance count for major objects in your app, such as pages and user controls. If there are more non-finalized instances than expected, you should investigate why these instances are not being released.

Best practices

  • Apps should not present raw device status info to the user, or attempt to dynamically parse or process the device status info on the device. A recommended use for the DeviceStatus API is to send the raw device status info to a web service in order to generate statistics or usage data. The DeviceName property may also be used to identify a device in order to mitigate known bugs that are specific to that device.

Memory usage example

The following example shows one way to monitor your app’s memory usage. It sets up a timer to display the app’s memory usage every 10 seconds.

public partial class MainPage : PhoneApplicationPage
    {
        DispatcherTimer timer;

        // Constructor
        public MainPage()
        {
            InitializeComponent();
            timer = new DispatcherTimer();
            timer.Interval = new TimeSpan(0,0,10);
            timer.Tick += new EventHandler(timer_Tick);
            timer.Start();
        }

        void timer_Tick(object sender, EventArgs e)
        {
            try
            {
                // These are TextBlock controls that are created in the page’s XAML file.      
                MemoryTextBlock.Text = Microsoft.Phone.Info.DeviceStatus.ApplicationCurrentMemoryUsage.ToString();
                PeakMemoryTextBlock.Text = Microsoft.Phone.Info.DeviceStatus.ApplicationPeakMemoryUsage.ToString();
            }
            catch (Exception ex)
            {
                MemoryTextBlock.Text = ex.Message;
            }
        }
    }