Java tutorial
//package com.java2s; import android.content.Context; import android.util.TypedValue; public class Main { /** * Get dpi value from pixels. * @param pixels * @param context * @return */ public static int getDpiFromInteger(int pixels, Context context) { return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, pixels, context.getResources().getDisplayMetrics()); } }