Windows Phone 7 取得設備資訊
如果目前想要取得設備上一些資訊例如:設備製造商、設備ID、設備記憶體使用量等等一些相關訊息那我們就可以使用DeviceExtendedProperties類別來取得相關訊息,可獲取的設備屬性值如下:
Property Name |
Value Type |
Description |
DeviceManufacturer |
A string. 256 characters maximum. |
The name of the manufacturer of the device. There is no standard format for this string. It is recommended that the same value be used by every device from a manufacturer, but this is not enforced. This value may be empty. |
DeviceName |
A string. 256 characters maximum. |
The name of the device. There is no standard format for this string. This value may be empty. |
DeviceUniqueId |
A byte array. 20 bytes in length. |
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. |
DeviceFirmwareVersion |
A string. |
The firmware version running on the device. This is not the same as the OS version, which can be retrieved using System.Environment. It is recommended that the value be a string that can be parsed as a System.Version structure and that it be incremented in a logical manner as newer firmware is installed, but this is not required. This value may be empty. |
DeviceHardwareVersion |
A string. |
The hardware version running of the device. This is not the same as the OS version, which can be retrieved using System.Environment. It is recommended that the value be a string that can be parsed as a System.Version structure and that it be incremented in a logical manner as newer hardware is released, but this is not required. This value may be empty. |
DeviceTotalMemory |
A long integer. |
The device’s physical RAM size in bytes. This value will be less than the actual amount of device memory, but can be used for determining memory consumption requirements. |
ApplicationCurrentMemoryUsage |
A long integer. |
The current application’s memory usage in bytes. |
ApplicationPeakMemoryUsage |
A long integer. |
The current application’s peak memory usage in bytes. |
使用下列程式碼把裝置的每個屬性值都叫出來看一下吧
listBox1.Items.Add("DeviceManufacturer\r\n" + DeviceExtendedProperties.GetValue("DeviceManufacturer").ToString()+"\r\n");
listBox1.Items.Add("DeviceName\r\n" + DeviceExtendedProperties.GetValue("DeviceName").ToString() + "\r\n");
listBox1.Items.Add("DeviceUniqueId\r\n" + Convert.ToBase64String((byte[])DeviceExtendedProperties.GetValue("DeviceUniqueId")) + "\r\n");
listBox1.Items.Add("DeviceFirmwareVersion\r\n" + DeviceExtendedProperties.GetValue("DeviceFirmwareVersion").ToString() + "\r\n");
listBox1.Items.Add("DeviceHardwareVersion\r\n" + DeviceExtendedProperties.GetValue("DeviceHardwareVersion").ToString() + "\r\n");
listBox1.Items.Add("DeviceTotalMemory\r\n" + DeviceExtendedProperties.GetValue("DeviceTotalMemory").ToString() + "\r\n");
listBox1.Items.Add("ApplicationCurrentMemoryUsage\r\n" + DeviceExtendedProperties.GetValue("ApplicationCurrentMemoryUsage").ToString() + "\r\n");
listBox1.Items.Add("ApplicationPeakMemoryUsage\r\n" + DeviceExtendedProperties.GetValue("ApplicationPeakMemoryUsage").ToString() + "\r\n");
我覺得裡面DeviceUniqueId很重要可以拿來做身份確認或是註冊使用,ApplicationCurrentMemoryUsage可以判斷記憶體使用量如果快爆了就可以秀一些訊息之類警告,如果你的應用程式想要綁機器或是製造商就可以採用DeviceManufacturer、DeviceName。