如何获取Windows Phone 8.1的设备唯一ID?

时间:2015-08-21 11:21:00

标签: c# windows-phone-8.1 unique-id

我想要back_end服务(ws)的唯一设备ID,我找到了以下参考

  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("-", "");
    }//Note: This function may throw an exception. 

但是,我无法理解代码,每次我为我的设备获得相同的Id(64个字符串),我想知道它是否适用? 我也找不到MSDN的任何参考资料

谢谢

1 个答案:

答案 0 :(得分:2)

这可能有所帮助:

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

    HashAlgorithmProvider hasher = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Md5);
    IBuffer hashed = hasher.HashData(hardwareId);

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

有关文档,请查看GetPackageSpecificToken 类中的HardwareIdentification方法。

相关问题