简体   繁体   English

在Windows Phone 8下获取唯一设备ID(UDID)

[英]Get Unique Device ID (UDID) under Windows Phone 8

Is there any unique device ID (UDID) or any similar ID I can read out on Windows Phone 8 (WP8) that doesn't change with hardware changes, app-reinstallation etc.? 是否有任何唯一的设备ID(UDID)或任何类似的ID,我可以在Windows Phone 8(WP8)上读取,不会随硬件更改,应用程序重新安装等而改变?

In older Windows Phone versions there were such IDs: WP7: Device Status for Windows Phone 在较旧的Windows Phone版本中,存在以下ID:WP7: Windows Phone的设备状态

WP7.1: DeviceStatus Class WP7.1: DeviceStatus类

But they doesn't work anymore with SDK 8.0. 但是它们不再适用于SDK 8.0。

Why I ask: The idea is that a user gets some free credits with the first start of the the app and I want to avoid that the user just re-installs the app for getting new free credits. 为什么我问:想法是用户在第一次启动应用程序时获得一些免费信用,我想避免用户只是重新安装应用程序以获得新的免费信用。 A registration with email or phone number could solve this, but if I can, I don't want do bother users at the first start with a registration. 使用电子邮件或电话号码注册可以解决这个问题,但如果可以,我不希望在第一次注册时打扰用户。

---///---SOLUTION---------- - -/// - -解 - - - - -

I can confirm that DeviceExtendedProperties.GetValue("DeviceUniqueId") still works in WP 8.0. 我可以确认DeviceExtendedProperties.GetValue(“DeviceUniqueId”)仍然可以在WP 8.0中运行。 Got a little bit confused when I read the following text: 当我阅读以下文字时有点困惑:

In Windows Phone OS 7.0, this class was used to query device-specific properties. 在Windows Phone OS 7.0中,此类用于查询特定于设备的属性。 In Windows Phone OS 7.1, most of the properties in DeviceExtendedProperties were deprecated, and the new DeviceStatus class should be used instead. 在Windows Phone OS 7.1中,不推荐使用DeviceExtendedProperties中的大多数属性,而应使用新的DeviceStatus类。 However, where appropriate, you can still use any of the below properties that are not deprecated. 但是,在适当的情况下,您仍然可以使用以下任何未弃用的属性。

MSDN:DeviceExtendedProperties Class MSDN:DeviceExtendedProperties类

I can run the following code, delete the app and re-install it and get the same ID: 我可以运行以下代码,删除应用程序并重新安装它并获得相同的ID:

byte[] myDeviceID = (byte[])Microsoft.Phone.Info.DeviceExtendedProperties.GetValue("DeviceUniqueId");
string DeviceIDAsString = Convert.ToBase64String(myDeviceID);
MessageBox.Show(DeviceIDAsString);

我还没有开始为Windows Phone 8开发,仍然在7,但您仍然应该能够使用原始的DeviceExtendedProperties类来撤回设备唯一ID。

DeviceExtendedProperties.GetValue("DeviceUniqueId")

I've had this issue with returning the null value. 我有这个问题,返回null值。 Then remembered that it needs to be switched on. 然后记得它需要打开。

In WMAppManifest.xml -> Capabilities tab -> switch on ID_CAP_IDENTITY_DEVICE WMAppManifest.xml - > Capabilities选项卡 - >打开ID_CAP_IDENTITY_DEVICE

There's a twist to this DeviceUniqueId - it is unique only for one publisher. 这个DeviceUniqueId有一个扭曲 - 它只对一个发布者是唯一的。 So it is not really device-wide unique identifier but unique device id for one publisher. 因此,它不是设备范围内的唯一标识符,而是一个发布商的唯一设备ID。 We have noticed when we worked on some customer project where we tried to identify the same phone from different accounts (customer publishes under two different accounts). 我们注意到,当我们处理一些客户项目时,我们尝试从不同的帐户识别相同的电话(客户在两个不同的帐户下发布)。

You can get your own wp8 device Id by DeviceExtendedProperties.GetValue("DeviceUniqueId") Here is the simple way to get deviceId as a string 您可以通过DeviceExtendedProperties.GetValue(“DeviceUniqueId”)获取您自己的wp8设备ID以下是将deviceId作为字符串获取的简单方法

byte[] id = (byte[])Microsoft.Phone.Info.DeviceExtendedProperties.GetValue("DeviceUniqueId");
 string   deviceID = Convert.ToBase64String(id);

By not providing DeviceUniqueId in Windows Phone 8 and Windows 8, Microsoft tried to avoid User Tracking but with increased pressure from Dev community, they are bringing it back again. 由于未在Windows Phone 8和Windows 8中提供DeviceUniqueId,微软试图避免用户跟踪,但是由于Dev社区的压力越来越大,他们又将其重新带回来。

In Windows 8.1, Microsoft has introduced a new AdvertisingId API and may also bring similar Id to identify a unique user across apps in subsequent Windows Phone 8.1/9 versions. 在Windows 8.1中,Microsoft引入了一个新的AdvertisingId API,并且还可能带来类似的ID来识别后续Windows Phone 8.1 / 9版本中的应用程序中的唯一用户。

I used this: 我用过这个:

    private static String getDeviceId()
        {
            byte[] id = (byte[])Microsoft.Phone.Info.DeviceExtendedProperties.GetValue("DeviceUniqueId");
            return BitConverter.ToString(id).Replace("-", string.Empty);
        }

But the key is to Check the ID_CAP_IDENTITY_DEVICE in WMAppManifest, or else it throws error. 但关键是检查WMAppManifest中的ID_CAP_IDENTITY_DEVICE,否则会引发错误。

我发现这是一个新的HostInformation.PublisherHostId属性更多信息,请访问http://msdn.microsoft.com/en-us/library/windowsphone/develop/windows.phone.system.analytics.hostinformation.publisherhostid.aspx ..

string myDeviceID = (byte[])DeviceExtendedProperties.GetValue("DeviceUniqueId");
string DeviceIDAsString = Convert.ToBase64String(myDeviceID);

I have used this for windows phone unique device Id. 我用过这个用于windows phone的独特设备ID。

The answers above work for Windows Phone 7 and 8 Silverlight. 上面的答案适用于Windows Phone 7和8 Silverlight。 However, they will not work for Windows Phone RT (Universal) or Store Apps since the SDK does not have this dll library (Microsoft.Phone). 但是,它们不适用于Windows Phone RT(通用)或商店应用程序,因为SDK没有此dll库(Microsoft.Phone)。

This is how you get the device ID and Name (and possibly other info) on Windows Phone 8.1 RT (Universal/Store Apps). 这是您在Windows Phone 8.1 RT(通用/商店应用程序)上获取设备ID和名称(以及可能的其他信息)的方式。

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

More details about reading the device info on Windows RT can be found here 有关在Windows RT上阅读设备信息的更多详细信息,请访问此处

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM