Java tutorial
//package com.java2s; //License from project: Open Source License import android.content.Context; import android.util.DisplayMetrics; import android.view.WindowManager; public class Main { /** * Method getDensity() used to get the Device's Density. With this function, * we can use for checking the device's density and supporting for other * devices. * * @param context * The Application Context. * @return Integer Type. */ public static int getDensity(Context context) { final WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); final DisplayMetrics metrics = new DisplayMetrics(); wm.getDefaultDisplay().getMetrics(metrics); return metrics.densityDpi; } }