Search code examples
windows-phone-8.1deviceunique-id

Windows Phone 8.1: DeviceExtendedProperties or DeviceStatus for Device Unique ID


I want to get the Device ID in Windows Phone 8.1.

The DeviceExtendedProperties or DeviceStatus are not available in WP8.1 (there is no Microsoft.Phone.Info namespace). I've just found the EasClientDeviceInformation class that I can't get the Id from it. There is an exception in the Id property:

enter image description here

And other properties are't unique.

There is another solution here but I don't know if it is safe or reliable to use: (?)
https://stackoverflow.com/a/23537207/3682369


Solution

  • Yes, you can use the GetPackageSpecificToken(). I have looked into it and haven't found any other way. Although MSDN says that the Id property contains some hardware info, it's actually an unique value for any device, even of the same model. So you can use it to identify the user's device.

    This is how I use it in my application. Feel free to use my code:

    private string GetDeviceId()
    {
        var token = Windows.System.Profile.HardwareIdentification.GetPackageSpecificToken(null);
        var hardwareId = token.Id;
        var dataReader = Windows.Storage.Streams.DataReader.FromBuffer(hardwareId);
    
        byte[] bytes = new byte[hardwareId.Length];
        dataReader.ReadBytes(bytes);
    
        return BitConverter.ToString(bytes).Replace("-", "");
    }