Device information

This article describes how you can use the .NET Multi-platform App UI (.NET MAUI) IDeviceInfo interface to read information about the device the app is running on.

The default implementation of the IDeviceInfo interface is available through the DeviceInfo.Current property. Both the IDeviceInfo interface and DeviceInfo class are contained in the Microsoft.Maui.Devices namespace.

Read device info

The IDeviceInfo interface provides many properties that describe the device, such as the manufacturer and idiom. The following example demonstrates reading the device info properties:

private void ReadDeviceInfo()
{
    System.Text.StringBuilder sb = new System.Text.StringBuilder();

    sb.AppendLine($"Model: {DeviceInfo.Current.Model}");
    sb.AppendLine($"Manufacturer: {DeviceInfo.Current.Manufacturer}");
    sb.AppendLine($"Name: {DeviceInfo.Name}");
    sb.AppendLine($"OS Version: {DeviceInfo.VersionString}");
    sb.AppendLine($"Refresh Rate: {DeviceInfo.Current}");
    sb.AppendLine($"Idiom: {DeviceInfo.Current.Idiom}");
    sb.AppendLine($"Platform: {DeviceInfo.Current.Platform}");

    bool isVirtual = DeviceInfo.Current.DeviceType switch
    {
        DeviceType.Physical => false,
        DeviceType.Virtual => true,
        _ => false
    };

    sb.AppendLine($"Virtual device? {isVirtual}");

    DisplayDeviceLabel.Text = sb.ToString();
}

Get the device platform

The IDeviceInfo.Platform property represents the operating system the app is running on. The DevicePlatform type provides a property for each operating system:

  • DevicePlatform.Android
  • DevicePlatform.iOS
  • DevicePlatform.macOS
  • DevicePlatform.MacCatalyst
  • DevicePlatform.tvOS
  • DevicePlatform.Tizen
  • DevicePlatform.WinUI
  • DevicePlatform.watchOS
  • DevicePlatform.Unknown

The following example demonstrates checking if the DeviceInfo.Platform property matches the Android operating system:

private bool IsAndroid() =>
    DeviceInfo.Current.Platform == DevicePlatform.Android;

Get the device type

The DeviceInfo.Idiom property represents the type of device the app is running on, such as a desktop computer or a tablet. The DeviceIdiom type provides a property for each type of device:

  • DeviceIdiom.Phone
  • DeviceIdiom.Tablet
  • DeviceIdiom.Desktop
  • DeviceIdiom.TV
  • DeviceIdiom.Watch
  • DeviceIdiom.Unknown

The following example demonstrates comparing the DeviceInfo.Idiom value to a DeviceIdiom property:

private void PrintIdiom()
{
    if (DeviceInfo.Current.Idiom == DeviceIdiom.Desktop)
        Console.WriteLine("The current device is a desktop");
    else if (DeviceInfo.Current.Idiom == DeviceIdiom.Phone)
        Console.WriteLine("The current device is a phone");
    else if (DeviceInfo.Current.Idiom == DeviceIdiom.Tablet)
        Console.WriteLine("The current device is a Tablet");
}

Device type

IDeviceInfo.DeviceType property an enumeration to determine if the application is running on a physical or virtual device. A virtual device is a simulator or emulator.

bool isVirtual = DeviceInfo.Current.DeviceType switch
{
    DeviceType.Physical => false,
    DeviceType.Virtual => true,
    _ => false
};

Platform differences

This section describes the platform-specific differences with the device information.

No platform differences.