Almost two years ago we discussed about “Microsoft.Phone.Info.DeviceStatus” class to retrieve Windows Phone device information in your application. In addition to those, there are some more APIs to fetch more details which is available as extended properties set.
Today in this post, we will learn about the API and the way to fetch those additional details in your application. Continue reading to know more about it.
Know about the API
Earlier in the post “Windows Phone 7 (Mango) Tutorial - 15 - Detecting Device Information”, we learnt how to detect the device information using the APIs available in the SDK. We also learnt how to detect whether any Keyboard has been installed with the device, whether the device is running under battery or using any external power supply. In addition to this, we also learnt the way to detect about the memory of the device and other device information.
In Windows Phone 7 and Windows Phone 8 SDK, addition to Microsoft.Phone.Info.DeviceStatus, there is another security safe static class named “DeviceExtendedProperties” present under the same namespace “Microsoft.Phone.Info” that provides additional details about the Windows Phone device where it is running.
The class has two public methods named “GetValue” and “TryGetValue” which return the information based on the property name that you pass as the method parameter.
Deprecated API Warning
In Windows Phone OS 7.0, this class was used to query device-specific properties. In Windows Phone OS 7.1, most of the properties in DeviceExtendedProperties were deprecated and the new DeviceStatus class should be used instead. However, in case you need further details, you can still use any of the below properties that were not yet deprecated:
|ApplicationCurrentMemoryUsage||The current application’s memory usage in bytes.|
|ApplicationPeakMemoryUsage||The current application's peak memory usage in bytes.|
|ApplicationWorkingSetLimit||The working set limit in bytes. This property applies to Windows Phone OS 7.1 and higher.|
|DeviceFirmwareVersion||The firmware version running on the device. This is not the same as the OS version, which can be retrieved using System.Environment.|
|DeviceHardwareVersion||The hardware version running of the device. This is not the same as the OS version, which can be retrieved using System.Environment.|
|DeviceManufacturer||The name of the manufacturer of the device. There is no standard format for this string. This value may be empty.|
|DeviceName||The name of the device. There is no standard format for this string. This value may be empty.|
|DeviceTotalMemory||The physical RAM size of the device in bytes. This value will be less than the actual amount of device memory but can be used for determining memory consumption requirements.|
|DeviceUniqueId||A unique hash for the device. This value will be constant across all applications and will not change if the phone is updated with a new version of the operating system. Applications should not use this to identify users because the device ID will remain unchanged even if ownership of the device is transferred.|
For a recent version and usage of this API, check out this blog post: “Windows Phone 7 (Mango) Tutorial - 15 - Detecting Device Information”.
Usage of DeviceExtendedProperties
If you can not use the latest API and want to use the DeviceExtendedProperties class, you need to call the static method GetValue or TryGetValue of the class with the appropriate property name as the parameter to the method as shown in the below code snippet for your reference:
var appCurrentMemoryUsage = DeviceExtendedProperties.GetValue("ApplicationCurrentMemoryUsage");
var appPeakMemoryUsage = DeviceExtendedProperties.GetValue("ApplicationPeakMemoryUsage");
var appWorkingSetLimit = DeviceExtendedProperties.GetValue("ApplicationWorkingSetLimit");
var deviceFirmwareVersion = DeviceExtendedProperties.GetValue("DeviceFirmwareVersion");
var deviceHardwareVersion = DeviceExtendedProperties.GetValue("DeviceHardwareVersion");
var deviceManufacturer = DeviceExtendedProperties.GetValue("DeviceManufacturer");
var deviceName = DeviceExtendedProperties.GetValue("DeviceName");
var deviceTotalMemory = DeviceExtendedProperties.GetValue("DeviceTotalMemory");
var deviceUniqueId = DeviceExtendedProperties.GetValue("DeviceUniqueId");
Once you retrieve the values, you can do your stuffs like showing them to user or whatever that you wanted to do. Remember that, if you run them inside emulator, you will get 0.0.0.0 as the version number but it will work perfectly in the actual physical device. Also, the device unique ID is specific to the device and will not change if you update the firmware or reset the factory settings. So, use it based on your requirement.
Stay tuned with me for updates and technical discussions on Twitter, Facebook and Google+. Don’t forget to subscribe to my blog’s RSS feed and email newsletter. Share your feedback about this post and the other blog posts.