Java tutorial
//package com.java2s; //License from project: Apache License import android.app.Activity; import android.util.DisplayMetrics; import android.view.Display; import android.view.WindowManager; public class Main { public static int getDpi(Activity activity) { WindowManager wm = activity.getWindowManager(); //wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE); Display dp = wm.getDefaultDisplay(); DisplayMetrics dm = new DisplayMetrics(); dp.getMetrics(dm); return dm.densityDpi; } }