Introduction:
In this article we are going to see how to get the Device information for managing the device. We will see how to make use of the Device detection API’s available with the Windows Phone 7 SDK to detect the Device information, Memory detection, Keyboard installed or not etc with the API.
To detect the device information, we are going to use the DeviceExtendedProperties class. We have different options to get the information of the device, network etc.. with the API. We will see only retrieving the device information here with this article. [more]
We are going to retrieve the below list of device information
S No |
Information |
Description |
1 |
DeviceUniqueId |
Gets device Unique ID. |
2 |
DeviceManufacturer |
Gets Device Manufacture details. |
3 |
ApplicationCurrentMemoryUsage |
Gets Application Memory Usage. |
4 |
ApplicationPeakMemoryUsage |
Gets Application Memory Leak Usage. |
5 |
DeviceName |
Gets the Device Name. |
6 |
DeviceFirmwareVersion |
Gets the Firmware Version. |
7 |
DeviceHardwareVersion |
Gets the Hardware Version. |
8 |
DeviceTotalMemory |
Gets the physical Memory RAM Usage. |
9 |
Power Source |
Indicates if the device works with power or battery. |
10 |
Iskeyboardpresent |
Indicates if any physical keyboard is installed with device |
11 |
IsKeyboardDeployed |
Indicates if the user deploy the physical keyboard |
12 |
ApplicationMemoryUsageLimit |
Gets the maximum amount of memory. |
Let us jump start to see the step by step process on how to implement the device information class to get the information and show it to the end users.
Steps:
Open Visual Studio 2010 and create a new Silverlight for Windows Phone 7 Application with a valid project name as shown in the screen below.
Now let us start with our design to see the device informations in one page. Once we are done with the design we can see the screen looks like below screen. Just copy the XAML code to get the same look and feel. Else we can directly drag and drop the controls from the tool box and design it as per the requirement.
XAML Code:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Now let us start with our code to get the device information and load it to the respective text blocks one by one as shown in the code below. We can use the Device Status class to get the details of the device properties except the device unique ID. We will write the code later to get the unique id of the device.
Code Behind:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Now let us write the code for getting the Device Unique ID as shown in the code below. We use the DeviceExtendedProperties property TryGetValue to get the Unique ID, since we get it as a byte array we do a conversion to the string and assign it to the text block as shown below.
Code Behind:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Now we are done with our code, let us build and execute the application by pressing F5 directly from the keyboard and we can see the application loaded to the Windows Phone 7 Emulator as shown in the screen below with the expected output.
Conclusion:
So in this article we have seen how to get the device information details and the device unique id using the Device Status class in detail.