How to get the Device Information in #UWP apps?


If you are building apps/game for Universal Windows Platform, you might want to retrieve the device information where the app/game is currently running. You might use this information to log details about any exception and/or to do specific action based on device details.

 

In this post, we will learn how to fetch the device information in UWP apps. Continue to read about the APIs exposed by Microsoft SDK. Don’t forget to read my other posts too and share your feedback.

 

How to get the Device Information in #UWP apps? (www.kunal-chowdhury.com)

 

In last post, we learned “How to get the Battery Information in #UWP apps?” I hope that the post was easy to read and was quite explanatory. Today we will learn how to get the device information.

 

Microsoft Windows SDK provides an API “AnalyticsInfo.VersionInfo”, available under “Windows.System.Profile” namespace. This returns “AnalyticsVersionInfo”, which can be used to extract DeviceFamily and DeviceFamilyVersion. DeviceFamilyVersion is actually a string representation but you have to parse it to unsigned long first and then do some bit operation to convert it to a version representation. Here is the code snippet:

 

// get the system family information
var deviceFamily = AnalyticsInfo.VersionInfo.DeviceFamily;
 
// get the system version number
var deviceFamilyVersion = AnalyticsInfo.VersionInfo.DeviceFamilyVersion;
var version = ulong.Parse(deviceFamilyVersion);
var majorVersion = (version & 0xFFFF000000000000L) >> 48;
var minorVersion = (version & 0x0000FFFF00000000L) >> 32;
var buildVersion = (version & 0x00000000FFFF0000L) >> 16;
var revisionVersion = (version & 0x000000000000FFFFL);
var systemVersion = $"{majorVersion}.{minorVersion}.{buildVersion}.{revisionVersion}";

 

There’s also another API class named “EasClientDeviceInformation”, which is a sealed class and present under the namespace “Windows.Security.ExchangeActiveSyncProvisioning”. The API returns you details about Manufacturer name, Model name, Operating System name, Hardware version of the system, Firmware version of the system etc. Here is the code snippet for your reference:

 

// get the device manufacturer, model name, OS details etc.
var clientDeviceInformation = new EasClientDeviceInformation();
var deviceManufacturer = clientDeviceInformation.SystemManufacturer;
var deviceModel = clientDeviceInformation.SystemProductName;
var operatingSystem = clientDeviceInformation.OperatingSystem;
var systemHardwareVersion = clientDeviceInformation.SystemHardwareVersion;
var systemFirmwareVersion = clientDeviceInformation.SystemFirmwareVersion;

 

Here is a screenshot of what it returns when executed on my laptop running Windows 10:

 

Windows 10 Universal Apps - Fetch Device Information (www.kunal-chowdhury.com)

 

Here is a screenshot of what it retuns when executed on my Lumia 1020 running Windows 10 Mobile:

 

Windows 10 Mobile Universal Apps - Fetch Device Information (www.kunal-chowdhury.com)

 

I hope that the post was useful and gave you detail insight of the API. Have any queries? Drop a line below in the comments section. I am also available on Twitter, Facebook and Google+. Do connect with me and subscribe to what I share on those social networking channels. Also do subscribe to my blog’s RSS feed and Email Newsletter to get the immediate notifications of new blog post.

 


If you have come this far, it means that you liked what you are reading. Why not reach little more and connect with me directly on Twitter, Facebook, Google+ and LinkedIn. I would love to hear your thoughts and opinions on my articles directly. Also, don't forget to share your views and/or feedback in the comment section below.

2 comments

  1. Hi,

    Can return serial number of device

    Thanks in advance

    ReplyDelete
  2. Hi, same question, need a unique ID for the device that will be constant across boots.

    ReplyDelete

 
© 2008-2016 Kunal-Chowdhury.com - Microsoft Technology Blog for developers and consumers | Designed by Kunal Chowdhury
Back to top