Android Project: DPI

Does anyone know how to calculate the DPI in an Android Project?
I’ve got the current screen resolution, but I can’t work out how to get the actual screen size in inches.

Assuming you’re using .NET 6 (MG 3.8.1): add Maui Essentials (replaces Xamarin Essentials) via .csproj:
<UseMauiEssentials>true</UseMauiEssentials>

Getting DPI and other display info: Device Display Information - .NET MAUI | Microsoft Learn

2 Likes

In your Activity1.cs:

using Android.Util;

DisplayMetrics metrics = new DisplayMetrics();
WindowManager.DefaultDisplay.GetMetrics(metrics);
float DisplayDotsPerInchX = metrics.Xdpi;
float DisplayDotsPerInchY = metrics.Ydpi;