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.

 

Have a question? Or, a comment? Let's Discuss it below...

dhgate

Thank you for visiting our website!

We value your engagement and would love to hear your thoughts. Don't forget to leave a comment below to share your feedback, opinions, or questions.

We believe in fostering an interactive and inclusive community, and your comments play a crucial role in creating that environment.