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.