2015-08-21 15 views
6

Voglio Device ID unico per il servizio back_end (WS) per che ho trovato seguente riferimentoCome posso ottenere l'ID univoco del dispositivo per Windows Phone 8.1?

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. 

ma, non riesco a capire il codice, ogni volta che mi stesso ID per il mio dispositivo (64 stringa di caratteri) , Voglio sapere che è applicabile o no? Non riuscivo a trovare alcun riferimento da MSDN anche

Grazie

risposta

2

Questo può aiutare:

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

Per la documentazione, dare un'occhiata al metodo GetPackageSpecificToken nella classe HardwareIdentification.

+0

Invece di "MD5" * hardcoded * è possibile utilizzare 'HashAlgorithmNames.Md5' –

+0

@KristianVukusic Grazie. Ho aggiornato la mia risposta. –

+0

Questo PackageSpecificToken viene modificato dopo aver modificato il profilo hardware (scollegare BT o altro). Non mi fiderei di questo. Forse solo per scopi pubblicitari. – Tertium

Problemi correlati