【问题标题】:How to get Device Id in Windows 8 Metro app如何在 Windows 8 Metro 应用程序中获取设备 ID
【发布时间】:2012-10-15 10:23:27
【问题描述】:

如何在Windows Store App(Metro App)中获取唯一设备?

我们可以使用吗:

Windows.System.Profile.HardwareIdentification.GetPackageSpecificToken(null);

 Windows.System.Profile.HardwareToken hToke = Windows.System.Profile.HardwareIdentification.GetPackageSpecificToken(null);
IBuffer hardwareId = hToke.Id;
IBuffer signature = hToke.Signature;
IBuffer certificate = hToke.Certificate;
DataReader reader = Windows.Storage.Streams.DataReader.FromBuffer(hardwareId);
byte[] ar = new Byte[hardwareId.Length];
reader.ReadBytes(ar);
string i = ar.ToString();
string id = System.Text.Encoding.Unicode.GetString(ar, 0, ar.Length);
System.Diagnostics.Debug.WriteLine("ID" + Convert.ToBase64String(ar));

找到的第一个网络适配器的网络适配器 ID

IReadOnlyCollection<Windows.Networking.Connectivity.ConnectionProfile> profiles =
Windows.Networking.Connectivity.NetworkInformation.GetConnectionProfiles();
Windows.Networking.Connectivity.NetworkAdapter na = profiles.First<Windows.Networking.Connectivity.ConnectionProfile>().NetworkAdapter;
string nid =  na.NetworkAdapterId.ToString();

【问题讨论】:

    标签: microsoft-metro windows-runtime


    【解决方案1】:

    是的,这是suggested方式:

       private string GetHardwareId()
        {
            var token = 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);
        }  
    

    或者,您对这种方法有疑问?

    【讨论】:

    • 我可以通过这个获得 ID。但问题是同一设备上的不同应用程序会给出不同的 ID。我需要一个 ID,该 ID 对于该设备上的所有应用程序都应该是唯一的
    • 那么在连接配置文件中使用第一个适配器的 NetworkAdapterId 怎么样。我认为第一个适配器总是以太网。那么使用 NetworkAdapterId 作为唯一设备 ID 怎么样?
    【解决方案2】:

    这是我发现的另一种方式:

    Windows.Security.ExchangeActiveSyncProvisioning.EasClientDeviceInformation deviceInfo = 
      new Windows.Security.ExchangeActiveSyncProvisioning.EasClientDeviceInformation();
    
    var myDeviceID = deviceInfo.Id;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多