2014-04-27 98 views
27

如何在Windows Phone 8.1中获取设备唯一ID?使用DeviceExtendedProperties.GetValue("DeviceUniqueId")的旧方式不适用于Windows通用应用。Windows Phone 8.1中的设备唯一ID

+0

任何示例?我在这里问这个问题,以及:http://stackoverflow.com/questions/36004003/windows-phone-device-unique-id –

回答

23

请注意,当您编写通用应用程序时,它不仅可以安装在手机上。虽然在电话上技术上硬件配置是相同的,但在其他设备上,它可以改变,因此它的ID。这是我认为没有这种通用的方法来获得ID。 (更多信息,你可以找到also here)。

您可以看看HardwareIdentification class及其方法GetPackageSpecificToken

HardwareToken myToken = HardwareIdentification.GetPackageSpecificToken(null); 
IBuffer hardwareId = myToken.Id; 

还有一个Guidance on using the App Specific Hardware ID (ASHWID) to implement per-device app logic

+2

如果你想使用它,你必须记住,这个ID会改变,当你更改应用程序签名证书 – Johniak

+0

@Johniak谢谢你的支持。 – Romasz

+0

@Romasz'HardwareIdentification.GetPackageSpecificToken'取决于Package id/name。是否有任何其他ID对于安装在同一设备上的所有应用程序显示相同? –

31
private string GetDeviceID() 
{ 
    HardwareToken token = HardwareIdentification.GetPackageSpecificToken(null); 
    IBuffer hardwareId = token.Id; 

    HashAlgorithmProvider hasher = HashAlgorithmProvider.OpenAlgorithm("MD5"); 
    IBuffer hashed = hasher.HashData(hardwareId); 

    string hashedString = CryptographicBuffer.EncodeToHexString(hashed); 
    return hashedString; 
} 

希望得到这个帮助!

+0

为什么MD5呢?为什么不使用其他算法? – Apoorva

+9

我会将“MD5”替换为[HashAlgorithmNames.Md5](http://msdn.microsoft.com/en-us/library/windows.security.cryptography.core.hashalgorithmnames.md5.aspx)。 –

+0

您可以用Convert.ToBase64String替换CryptographicBuffer.EncodeToHexString,它会生成更短但仍然可读的字符串。 – Grigory