Windows Phone 8.1: DeviceExtendedProperties or Dev

2019-04-15 04:26发布

问题:

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:

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

回答1:

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("-", "");
}