Windows Phone 8.1: DeviceExtendedProperties or DeviceStatus for Device Unique ID

喜你入骨 提交于 2019-12-21 21:30:54

问题


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


来源:https://stackoverflow.com/questions/27601993/windows-phone-8-1-deviceextendedproperties-or-devicestatus-for-device-unique-id

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!