Java tutorial
//package com.java2s; import android.content.res.Resources; import android.util.DisplayMetrics; public class Main { public static float getScreenLargestWidth() { DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics(); int widthPixels = metrics.widthPixels; int heightPixels = metrics.heightPixels; float scaleFactor = metrics.density; float widthDp = widthPixels / scaleFactor; float heightDp = heightPixels / scaleFactor; return Math.max(widthDp, heightDp); } }