Java tutorial
//package com.java2s; import android.content.Context; import android.content.res.Resources; import android.util.DisplayMetrics; public class Main { private static int getResourceDisplayDensityDPI(Context context) { try { Resources resources = context.getResources(); DisplayMetrics displayMetrics = resources.getDisplayMetrics(); return displayMetrics.densityDpi; } catch (NullPointerException expected) { return DisplayMetrics.DENSITY_DEFAULT; } } }