问题描述
我想在Windows Phone 8.1 中获取设备ID.
I want to get the Device ID in Windows Phone 8.1.
DeviceExtendedProperties 或 DeviceStatus 在WP8.1中不可用(没有Microsoft.Phone.Info
命名空间).我刚刚发现无法从中获取Id
的EasClientDeviceInformation
类. Id
属性中有一个例外:
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:
其他属性也不是唯一.
这里还有另一种解决方案,但我不知道使用它是否安全或可靠:(?)
https ://stackoverflow.com/a/23537207/3682369
There is another solution here but I don't know if it is safe or reliable to use: (?)
https://stackoverflow.com/a/23537207/3682369
推荐答案
是的,您可以使用GetPackageSpecificToken()
.我已经调查过,但没有找到其他方法.尽管MSDN说Id
属性包含一些硬件信息,但实际上对于任何设备,即使是同一型号,它都是唯一的值.因此,您可以使用它来识别用户的设备.
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("-", "");
}
这篇关于Windows Phone 8.1:设备唯一ID的DeviceExtendedProperties或DeviceStatus的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!