aouw0w
Last Updated: September 09, 2019
·
1.203K
· feritarslan

WindowsPhone DeviceInfo Helper

Microsoft.Phone.Info Namespace is used to retrieve information about the device and anonymous identifier information about the user.

public enum DeviceKey
{
   DeviceName,
   DeviceUniqueId,
   DeviceManufacturer,
   ApplicationCurrentMemoryUsage,
   ApplicationPeakMemoryUsage,
   DeviceFirmwareVersion,
   DeviceHardwareVersion,
   DeviceTotalMemory
}

DeviceName
The name of the device. There is no standard format for this string. This value may be empty.

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.

DeviceManufacturer
The name of the manufacturer of the device. There is no standard format for this string. We recommend that the same value be used by every device from a manufacturer, but this is not enforced. This value may be empty.

ApplicationCurrentMemoryUsage
The current application’s memory usage in bytes.

ApplicationPeakMemoryUsage
The current application's peak memory usage in bytes.

DeviceFirmwareVersion
The firmware version running on the device. This is not the same as the OS version, which can be retrieved using System.Environment. This value may be empty.

DeviceHardwareVersion
The hardware version running of the device. This is not the same as the OS version, which can be retrieved using System.Environment. 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.

How to get device extended properties.

public static string GetDeviceInfo(DeviceKey key)
{
    string result = string.Empty;
    object deviceInfo;

    if (DeviceExtendedProperties
          .TryGetValue(key.ToString(), 
            out deviceInfo))
    {
        result = deviceInfo.ToString();
    }
    return result;
}

How to get anonymous identifier.

public static string GetAnonymousID()
{
    string anID = UserExtendedProperties
                      .GetValue("ANID") as string;
    return anID.Substring(2, 32);
}

Usage

string deviceName = DeviceInfoHelper
      .GetDeviceInfo(DeviceInfoHelper
           .DeviceKey.DeviceName);

Reference: MSDN & http://ben.ferit.im