2014-04-27 12 views
27

Come ottenere l'ID univoco del dispositivo in Windows Phone 8.1? Il vecchio modo di utilizzare DeviceExtendedProperties.GetValue("DeviceUniqueId") non funziona per l'app di Windows universale.ID univoco del dispositivo in Windows Phone 8.1

+0

Qualche esempio? Sto facendo questa domanda anche qui: http://stackoverflow.com/questions/36004003/windows-phone-device-unique-id –

risposta

23

Si noti che quando si scrive Universal App, può essere installato non solo sul telefono. Mentre sul telefono tecnicamente la configurazione hardware è la stessa, su altri dispositivi può cambiare e quindi il suo ID. Penso che non ci sia un metodo così universale per ottenere l'identità. (maggiori informazioni potete trovare also here).

Si può avere uno sguardo a HardwareIdentification class e il suo metodo GetPackageSpecificToken:

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

C'è anche una Guidance on using the App Specific Hardware ID (ASHWID) to implement per-device app logic.

+2

Se vuoi usarlo devi ricordare che questo ID cambierà quando tu cambia il certificato di firma dell'app – Johniak

+0

@Johniak Grazie per averlo eliminato. – Romasz

+0

@Romasz 'HardwareIdentification.GetPackageSpecificToken' dipende dall'ID/nome del pacchetto. C'è qualche altro ID che appare uguale per tutte le app installate sullo stesso dispositivo? –

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

Spero che questo aiuto!

+0

Perché MD5 però? Perché non qualsiasi altro algoritmo ?? – Apoorva

+9

Sostituire "MD5" in [HashAlgorithmNames.Md5] (http://msdn.microsoft.com/en-us/library/windows.security.cryptography.core.hashalgorithmnames.md5.aspx). –

+0

È possibile sostituire CryptographicBuffer.EncodeToHexString con Convert.ToBase64String, producendo una stringa più breve ma ancora leggibile. – Grigory

Problemi correlati