Java tutorial
//package com.java2s; //License from project: Apache License import android.content.Context; import android.util.DisplayMetrics; public class Main { /** * Gets device's display density. * @since 0.1.0 * @param aContext The context from which the display metrics information is retrieved. * @return The density in String or an empty String if display metrics is not retrievable. */ public static String getScreenDpi(Context aContext) { DisplayMetrics metrics = aContext.getResources().getDisplayMetrics(); switch (metrics.densityDpi) { case DisplayMetrics.DENSITY_LOW: return "ldpi"; case DisplayMetrics.DENSITY_MEDIUM: return "mdpi"; case DisplayMetrics.DENSITY_HIGH: return "hdpi"; case DisplayMetrics.DENSITY_XHIGH: return "xhdpi"; case DisplayMetrics.DENSITY_XXHIGH: return "xxhdpi"; case DisplayMetrics.DENSITY_XXXHIGH: return "xxxhdpi"; default: return ""; } } }