Java tutorial
//package com.java2s; import android.app.Activity; import android.content.Context; import android.util.DisplayMetrics; import android.view.Display; import android.view.WindowManager; public class Main { private static Context sContext = null; public static float getDPI() { if (sContext != null) { DisplayMetrics metrics = new DisplayMetrics(); WindowManager wm = ((Activity) sContext).getWindowManager(); if (wm != null) { Display d = wm.getDefaultDisplay(); if (d != null) { d.getMetrics(metrics); return (metrics.density * 160.0f); } } } return -1.0f; } }