Get Unique Device ID (UDID) under Windows Phone 8

2019-01-13 02:57发布

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.?

In older Windows Phone versions there were such IDs: WP7: Device Status for Windows Phone

WP7.1: DeviceStatus Class

But they doesn't work anymore with 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. 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. In Windows Phone OS 7.1, most of the properties in DeviceExtendedProperties were deprecated, and the new DeviceStatus class should be used instead. However, where appropriate, you can still use any of the below properties that are not deprecated.

MSDN:DeviceExtendedProperties Class

I can run the following code, delete the app and re-install it and get the same ID:

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

9条回答
再贱就再见
2楼-- · 2019-01-13 03:32

You can get your own wp8 device Id by DeviceExtendedProperties.GetValue("DeviceUniqueId") Here is the simple way to get deviceId as a string

byte[] id = (byte[])Microsoft.Phone.Info.DeviceExtendedProperties.GetValue("DeviceUniqueId");
 string   deviceID = Convert.ToBase64String(id);
查看更多
Luminary・发光体
4楼-- · 2019-01-13 03:39
string myDeviceID = (byte[])DeviceExtendedProperties.GetValue("DeviceUniqueId");
string DeviceIDAsString = Convert.ToBase64String(myDeviceID);

I have used this for windows phone unique device Id.

查看更多
何必那么认真
5楼-- · 2019-01-13 03:39

The answers above work for Windows Phone 7 and 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).

This is how you get the device ID and Name (and possibly other info) on Windows Phone 8.1 RT (Universal/Store Apps).

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

I have posted a blog post here explaining the differences, and more details about reading the device info on Windows RT can be found here

查看更多
淡お忘
6楼-- · 2019-01-13 03:44

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.

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.

查看更多
来,给爷笑一个
7楼-- · 2019-01-13 03:46

There's a twist to this DeviceUniqueId - it is unique only for one publisher. So it is not really device-wide unique identifier but unique device id for one publisher. 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).

查看更多
登录 后发表回答