Telerik blogs
XamarinT2 Dark_1200x303

Two Xamarin.Essentials classes can provide much needed info about mobile devices: DeviceInfo and DeviceDisplay.

As mobile developers, sometimes we need to get information from mobile devices to be able to perform some determined actions using the data obtained. That’s why in this article we will learn how to get it through Xamarin Essentials. The topics will be divided in two groups: Device information and device display information.

Before Going into the Details, Let’s Learn Some Things ๐Ÿค“

โž– Xamarin Essentials: Is a cross-platform library that gives us access to useful information and native libraries from the device’s platform in order to simplify our lives when developing a mobile application. Some examples of the types of information we can obtain include: Device information, device sensor information, motion detectors, phone dialer, among many other interesting features to apply in our device in Xamarin Forms. ๐Ÿ˜

โž– Device information: Gives us access to the information of the device that is running our application.

โž– Device display information: Gives us access to the information about the device’s screen metrics our application is running on.

Device Information

To start, let’s add Xamarin Essentials references to our class:

using Xamarin.Essentials;

Once we’ve added the references, let’s explore the API’s properties:

๐Ÿ”น Model: Returns a string value and provides us the device model. (For example: x86_64 X.)

string Model = DeviceInfo.Model;

๐Ÿ”น Manufacturer: Returns a string value and provides us the device manufacturer. (For example: Apple.)

string Manufacturer = DeviceInfo.Manufacturer;

๐Ÿ”น Name: Returns a string value and provides us the device name. (For example: iPhone X.)

string Name = DeviceInfo.Name;

๐Ÿ”น Version: Returns a string value and provides us the device version. (For example: 12.2.)

string Version = DeviceInfo.VersionString;

๐Ÿ”น Platform: Returns a DevicePlatform value and provides us the device platform. Values can be: iOS, Android, UWP, Unknown. (For example: iOS.)

var Platforms = DeviceInfo.Platform;

๐Ÿ”น Idiom: Returns a DeviceIdiom value and provides us the device type that is running our application. Values can be: Phone, Desktop, TV, Tablet, Watch, Unknown. (For example: Phone.)

var Idiom = DeviceInfo.Idiom;

๐Ÿ”น DeviceType: Returns a DeviceType value and identifies if we are running the application on an emulator or physical device. (For example: Virtual.)

 var DeviceType = DeviceInfo.DeviceType;

Device Display Information

To get access, you just have to add the following code line the property that you need to use: DeviceDisplay.MainDisplayInfo

For example:

 double _density = DeviceDisplay.MainDisplayInfo.Density;

Now let’s learn the other properties:

Property name / Returned Value:Density / double. Height / double. Orientation / DisplayOrientation. Rotation / DisplayRotation. Width / double.

Thanks for reading my article! ๐Ÿ’š


About the Author

Leomaris Reyes

Leomaris Reyes is a Software Engineer from the Dominican Republic, with more than 5 years of experience. A Xamarin Certified Mobile Developer, she is also the founder of  Stemelle, an entity that works with software developers, training and mentoring with a main goal of including women in Tech. Leomaris really loves learning new things! ๐Ÿ’š๐Ÿ’• You can follow her: Twitter, LinkedIn , AskXammy and Medium.

Related Posts


Comments are disabled in preview mode.