47

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);
flexo
  • 1,099
  • 1
  • 9
  • 14
  • 4
    As far as I understand, there is a lot of pressure for mobile OS not to provide UDID because of the ability it gives to track users. So, the registration option is probably a better idea. Otherwise, in the future, UDID could no longer be available. [This has already happened in iOS](http://stackoverflow.com/questions/6993325/uidevice-uniqueidentifier-deprecated-what-to-do-now). – Davin Tryon Dec 20 '12 at 15:31
  • I know. Apple had the same problem and they 'mitigate' this by using a [vendor ID](http://stackoverflow.com/questions/11836225/ios6-udid-what-advantages-does-identifierforvendor-have-over-identifierforadve). So I thought Microsoft does something similar? Not? – flexo Dec 20 '12 at 15:51
  • To be honest, I'm not sure about Windows Phone 8 because I haven't developed against it. But in principle, we should try not to use static identifiers unless they are stored on a server. There has been talk of legislation in the EU about avoiding a way to track users on mobile devices. – Davin Tryon Dec 20 '12 at 15:53

9 Answers9

31

I haven't yet started to develop for Windows Phone 8, still on 7, but you still should be able to use the original DeviceExtendedProperties class to pull back the Device Unique ID.

DeviceExtendedProperties.GetValue("DeviceUniqueId")
Frazell Thomas
  • 5,913
  • 1
  • 18
  • 21
20

I've had this issue with returning the null value. Then remembered that it needs to be switched on.

In WMAppManifest.xml -> Capabilities tab -> switch on ID_CAP_IDENTITY_DEVICE

giacoder
  • 880
  • 7
  • 21
8

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

  • 1
    This sounds really important. Could you elaborate? Does this mean that a certain phone could get different ids depending on what app (linked to a publisher) tries to read it? – MEMark Dec 18 '13 at 17:17
  • 2
    It means two difference apps from the same publisher will retrieve the same DeviceUniqueId value from a given device, but apps written by a second publisher will retrieve a difference DeviceUniqueId. – Jon B Jan 09 '14 at 01:26
  • Please could you provide an example of publisher? – eeadev Oct 17 '14 at 09:27
4

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);
Jaihind
  • 2,762
  • 1
  • 10
  • 19
2

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.

prabh.arora
  • 129
  • 6
  • Hi Prabh Arora, thanks for sharing useful information. I have one query about AdvertisingId, can user reset or change this AdvertisingId at any point of time, because in case of iOS user can do as such. Please reply. Thanks in advance. – Anil Chahal Apr 14 '15 at 14:44
  • I just do some more r&d and found this article, http://en.kioskea.net/faq/34379-windows-8-1-prevent-apps-from-using-your-advertising-id User has a choice to prevent developers to get his AdvertisingId, so all n all we back to square one. If you found any other alternative to track with any other unique feature then please reply. – Anil Chahal Apr 14 '15 at 14:51
2

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.

CarmenA
  • 419
  • 12
  • 20
1

I found this a new HostInformation.PublisherHostId property More info at http://msdn.microsoft.com/en-us/library/windowsphone/develop/windows.phone.system.analytics.hostinformation.publisherhostid.aspx..

raevilman
  • 2,669
  • 1
  • 15
  • 24
1
string myDeviceID = (byte[])DeviceExtendedProperties.GetValue("DeviceUniqueId");
string DeviceIDAsString = Convert.ToBase64String(myDeviceID);

I have used this for windows phone unique device Id.

0

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

More details about reading the device info on Windows RT can be found here

Zoe
  • 23,712
  • 16
  • 99
  • 132
Has AlTaiar
  • 3,790
  • 1
  • 33
  • 36