Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get Device Unique Id for windows phone 8.1?

I want Unique Device Id for back_end service (ws) for that I found following reference

  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. 

but, I can't understand the code , every time I get same Id for my Device (64 character string ), I want to know that it is applicable or not ? I couldn't found any reference from MSDN also

Thank you

like image 218
Kushal Maniyar Avatar asked Aug 21 '15 11:08

Kushal Maniyar


1 Answers

This may help:

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;
}

For the documentation, have a look at the GetPackageSpecificToken method in the HardwareIdentification class.

like image 83
Stuart Avatar answered Oct 15 '22 08:10

Stuart