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

1

6

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

Legra answered 21/8, 2015 at 11:20 Comment(0)
G
2

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.

Grimbald answered 21/8, 2015 at 11:27 Comment(4)
Instead of the hardcoded "MD5" you can use HashAlgorithmNames.Md5Gifted
@KristianVukusic Thank you. I have updated my answer.Grimbald
This PackageSpecificToken is changed once you change hardware profile (unplug BT or something else). I'd not rely on it. Maybe only for ad purposes.Problem
Anyway if you use it you should handle its "drift": msdn.microsoft.com/en-US/library/windows/apps/…Problem

© 2022 - 2024 — McMap. All rights reserved.