Get the device name of your Windows Phone
I am updating my rubber duck app and I want to store the amount of ‘squeeck’s per device in roaming settings. So you can see the total but also how much you squeezed the duck on every device.
I am storing this as key value pair and the key is the device name.
So how do you get the device name? You can’t. There is (as far as I know) no API to get the device name.
So when searching around I found this trick which I am documenting for myself here in this post.
Windows.Networking.Proximity.PeerFinder.DisplayName will give you the name a user gave his device.
Not sure how robust it is yet. It seemed to work on my phone, but when I check the name in internet sharing in my emulators they say something like ‘Microsoft Virtual_6262’ but the API returns ‘Windows Phone’ so apparently these 2 aren’t the same. That’s ok since you can change the broadcast name for internet sharing in the UI and renaming your phone needs to be done when it’s connected to your PC.
Comments
Comment by Leon Zandman on 2015-01-03 23:38:11 -0800
Can’t you use GetPackageSpecificToken()? Or the ASHWID?
http://stackoverflow.com/questions/23321484/device-unique-id-in-windows-phone-8-1
Comment by Jeremy Sinclair on 2015-01-04 08:56:07 -0800
“It seemed to work on my phone, but when I check the name in internet sharing in my emulators they say something like ‘Microsoft Virtual_6262’ but the API returns ‘Windows Phone’ so apparently these 2 aren’t the same
You are correct. There are registry entries that are carrier/OEM-specific presets that contain the prefix for the broadcast name.
Comment by Matthijs Hoekstra on 2015-01-05 00:06:29 -0800
Nope, need the name of the phone to display (in my scenario) I want to track rubber duck squeezes per device and show the total. Still need to figure out if this will work on win8
Comment by Peter Foot on 2015-01-07 02:15:37 -0800
In 8.1 (SL or Windows XAML) you can use Windows.Security.ExchangeActiveSyncProvisioning.EasClientDeviceInformation and the FriendlyName property which should be the name the user has applied to the device (“Windows Phone” by default). You can also retrieve Model and Manufacturer from this class.