Here you can find the source of getScreenDensity(Context context)
public static int getScreenDensity(Context context)
//package com.java2s; import android.content.Context; import android.util.DisplayMetrics; import android.view.Display; import android.view.WindowManager; public class Main { private static DisplayMetrics _display_metrics = null; public static int getScreenDensity(Context context) { retrieveDisplayMetrics(context); return (int) (_display_metrics.density * DisplayMetrics.DENSITY_DEFAULT); }//from w ww .j a v a2 s . co m private static void retrieveDisplayMetrics(Context context) { if (_display_metrics == null) { Display display = ((WindowManager) context .getSystemService(Context.WINDOW_SERVICE)) .getDefaultDisplay(); _display_metrics = new DisplayMetrics(); display.getMetrics(_display_metrics); } } }